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
|
||||
----------------------------------------
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
#
|
||||
__version__ = '2.2.1'
|
||||
__version__ = '2.2.2.dev1'
|
||||
|
|
|
@ -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[:] = []
|
||||
|
|
4
setup.py
4
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()
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue