work around an apparent python2.4/python2.5 bug with subprocess.Popen,

causing jenkins failures.  Apparently "os.environ.popitem(name, None)"
is not the same as::

    try:
        del os.environ[name]
    except KeyError:
        pass
This commit is contained in:
holger krekel 2011-12-28 15:49:13 +00:00
parent f2c8a837af
commit fa6d5bd15b
3 changed files with 17 additions and 7 deletions

View File

@ -95,7 +95,10 @@ class monkeypatch:
self._setattr[:] = []
for dictionary, name, value in self._setitem:
if value is notset:
dictionary.pop(name, None)
try:
del dictionary[name]
except KeyError:
pass # was already deleted, so we have the desired state
else:
dictionary[name] = value
self._setitem[:] = []

View File

@ -67,12 +67,20 @@ def test_setitem_deleted_meanwhile():
monkeypatch.undo()
assert not d
def test_setenv_deleted_meanwhile():
@pytest.mark.parametrize("before", [True, False])
def test_setenv_deleted_meanwhile(before):
key = "qwpeoip123"
if before:
os.environ[key] = "world"
monkeypatch = MonkeyPatch()
monkeypatch.setenv('XYZ123', 'hello')
del os.environ['XYZ123']
monkeypatch.setenv(key, 'hello')
del os.environ[key]
monkeypatch.undo()
assert 'XYZ123' not in os.environ
if before:
assert os.environ[key] == "world"
del os.environ[key]
else:
assert key not in os.environ
def test_delitem():
d = {'x': 1}

View File

@ -436,8 +436,7 @@ def test_pytest_cmdline_main(testdir):
py.test.cmdline.main([__file__])
""")
import subprocess
popen = subprocess.Popen([sys.executable, str(p)],
stdout=subprocess.PIPE, env={})
popen = subprocess.Popen([sys.executable, str(p)], stdout=subprocess.PIPE)
s = popen.stdout.read()
ret = popen.wait()
assert ret == 0