diff options
author | Chris Withers <chris@withers.org> | 2019-05-02 13:21:18 +0100 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2019-05-02 13:21:18 +0100 |
commit | b66b5b9d75b19b4b8cb11beec9d0da0aab43a764 (patch) | |
tree | 126b3659e951abd51674ee2fc97f8d1822e2df0b /mock | |
parent | 536ffbb4a37054e2270d4ae56edb8e651f2c55b1 (diff) | |
download | mock-b66b5b9d75b19b4b8cb11beec9d0da0aab43a764.tar.gz |
Use basestring when checking for dictionary patching.
Fixes https://github.com/testing-cabal/mock/issues/458.
Diffstat (limited to 'mock')
-rw-r--r-- | mock/mock.py | 2 | ||||
-rw-r--r-- | mock/tests/testpatch.py | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/mock/mock.py b/mock/mock.py index 7f3bafe..5d4b420 100644 --- a/mock/mock.py +++ b/mock/mock.py @@ -1768,7 +1768,7 @@ class _patch_dict(object): def _patch_dict(self): values = self.values - if isinstance(self.in_dict, str): + if isinstance(self.in_dict, basestring): self.in_dict = _importer(self.in_dict) in_dict = self.in_dict clear = self.clear diff --git a/mock/tests/testpatch.py b/mock/tests/testpatch.py index 958ea7f..bbd6d26 100644 --- a/mock/tests/testpatch.py +++ b/mock/tests/testpatch.py @@ -656,6 +656,14 @@ class PatchTest(unittest.TestCase): test() + def test_patch_dict_with_unicode(self): + @patch.dict(u'os.environ', {'konrad_delong': 'some value'}) + def test(): + self.assertIn('konrad_delong', os.environ) + + test() + + def test_patch_dict_decorator_resolution(self): # bpo-35512: Ensure that patch with a string target resolves to # the new dictionary during function call |