robustify monkeypatch
This commit is contained in:
parent
f5f8695587
commit
40187ec9bb
|
@ -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
|
Changes between 2.2.0 and 2.2.1
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.2.1'
|
__version__ = '2.2.2.dev1'
|
||||||
|
|
|
@ -95,7 +95,7 @@ class monkeypatch:
|
||||||
self._setattr[:] = []
|
self._setattr[:] = []
|
||||||
for dictionary, name, value in self._setitem:
|
for dictionary, name, value in self._setitem:
|
||||||
if value is notset:
|
if value is notset:
|
||||||
del dictionary[name]
|
dictionary.pop(name, None)
|
||||||
else:
|
else:
|
||||||
dictionary[name] = value
|
dictionary[name] = value
|
||||||
self._setitem[:] = []
|
self._setitem[:] = []
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='py.test: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.2.1',
|
version='2.2.2.dev1',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
license='MIT license',
|
license='MIT license',
|
||||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||||
|
|
|
@ -59,6 +59,20 @@ def test_setitem():
|
||||||
monkeypatch.undo()
|
monkeypatch.undo()
|
||||||
assert d['x'] == 5
|
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():
|
def test_delitem():
|
||||||
d = {'x': 1}
|
d = {'x': 1}
|
||||||
monkeypatch = MonkeyPatch()
|
monkeypatch = MonkeyPatch()
|
||||||
|
|
Loading…
Reference in New Issue