diff --git a/CHANGELOG b/CHANGELOG index 30d7d905d..b2589061b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +Changes between 2.2.1 and 2.2.2.dev +---------------------------------------- + +- make monkeypatch more robust against intermediate dict/env deletions + Changes between 2.2.0 and 2.2.1 ---------------------------------------- diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 64697fb10..62b131259 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.2.1' +__version__ = '2.2.2.dev1' diff --git a/_pytest/monkeypatch.py b/_pytest/monkeypatch.py index 0a530b717..4107782e5 100644 --- a/_pytest/monkeypatch.py +++ b/_pytest/monkeypatch.py @@ -95,7 +95,7 @@ class monkeypatch: self._setattr[:] = [] for dictionary, name, value in self._setitem: if value is notset: - del dictionary[name] + dictionary.pop(name, None) else: dictionary[name] = value self._setitem[:] = [] diff --git a/setup.py b/setup.py index 026122d34..db275ebd9 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.2.1', + version='2.2.2.dev1', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], @@ -70,4 +70,4 @@ def make_entry_points(): return {'console_scripts': l} if __name__ == '__main__': - main() + main() \ No newline at end of file diff --git a/testing/test_monkeypatch.py b/testing/test_monkeypatch.py index 973811025..bc093ef5e 100644 --- a/testing/test_monkeypatch.py +++ b/testing/test_monkeypatch.py @@ -59,6 +59,20 @@ def test_setitem(): monkeypatch.undo() assert d['x'] == 5 +def test_setitem_deleted_meanwhile(): + d = {} + monkeypatch = MonkeyPatch() + monkeypatch.setitem(d, 'x', 2) + del d['x'] + monkeypatch.undo() + assert not d + +def test_setenv_deleted_meanwhile(): + monkeypatch = MonkeyPatch() + monkeypatch.setenv('XYZ123', 'hello') + monkeypatch.undo() + assert 'XYZ123' not in os.environ + def test_delitem(): d = {'x': 1} monkeypatch = MonkeyPatch()