fix unicode handling with new monkeypatch.setattr(import_path, value)
API. Thanks Rob Dennis. Fixes issue371.
This commit is contained in:
parent
47d2d20d81
commit
0d8392bc45
|
@ -1,6 +1,9 @@
|
|||
Changes between 2.4.2 and 2.4.3
|
||||
-----------------------------------
|
||||
|
||||
- fix unicode handling with new monkeypatch.setattr(import_path, value)
|
||||
API. Thanks Rob Dennis. Fixes issue371.
|
||||
|
||||
- In assertion rewriting mode on Python 2, fix the detection of coding
|
||||
cookies. See issue #330.
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
""" monkeypatching and mocking functionality. """
|
||||
|
||||
import os, sys
|
||||
from py.builtin import _basestring
|
||||
|
||||
def pytest_funcarg__monkeypatch(request):
|
||||
"""The returned ``monkeypatch`` funcarg provides these
|
||||
|
@ -28,7 +29,7 @@ def pytest_funcarg__monkeypatch(request):
|
|||
|
||||
def derive_importpath(import_path):
|
||||
import pytest
|
||||
if not isinstance(import_path, str) or "." not in import_path:
|
||||
if not isinstance(import_path, basestring) or "." not in import_path:
|
||||
raise TypeError("must be absolute import path string, not %r" %
|
||||
(import_path,))
|
||||
rest = []
|
||||
|
@ -85,7 +86,7 @@ class monkeypatch:
|
|||
import inspect
|
||||
|
||||
if value is notset:
|
||||
if not isinstance(target, str):
|
||||
if not isinstance(target, _basestring):
|
||||
raise TypeError("use setattr(target, name, value) or "
|
||||
"setattr(target, value) with target being a dotted "
|
||||
"import string")
|
||||
|
@ -115,7 +116,7 @@ class monkeypatch:
|
|||
"""
|
||||
__tracebackhide__ = True
|
||||
if name is notset:
|
||||
if not isinstance(target, str):
|
||||
if not isinstance(target, basestring):
|
||||
raise TypeError("use delattr(target, name) or "
|
||||
"delattr(target) with target being a dotted "
|
||||
"import string")
|
||||
|
|
|
@ -45,6 +45,12 @@ class TestSetattrWithImportPath:
|
|||
import _pytest
|
||||
assert _pytest.config.Config == 42
|
||||
|
||||
def test_unicode_string(self, monkeypatch):
|
||||
monkeypatch.setattr(u"_pytest.config.Config", 42)
|
||||
import _pytest
|
||||
assert _pytest.config.Config == 42
|
||||
monkeypatch.delattr(u"_pytest.config.Config")
|
||||
|
||||
def test_wrong_target(self, monkeypatch):
|
||||
pytest.raises(TypeError, lambda: monkeypatch.setattr(None, None))
|
||||
|
||||
|
|
Loading…
Reference in New Issue