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[:] = [] self._setattr[:] = []
for dictionary, name, value in self._setitem: for dictionary, name, value in self._setitem:
if value is notset: 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: else:
dictionary[name] = value dictionary[name] = value
self._setitem[:] = [] self._setitem[:] = []

View File

@ -67,12 +67,20 @@ def test_setitem_deleted_meanwhile():
monkeypatch.undo() monkeypatch.undo()
assert not d 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 = MonkeyPatch()
monkeypatch.setenv('XYZ123', 'hello') monkeypatch.setenv(key, 'hello')
del os.environ['XYZ123'] del os.environ[key]
monkeypatch.undo() 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(): def test_delitem():
d = {'x': 1} d = {'x': 1}

View File

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