[New-bugs-announce] [issue5051] test_update2 in test_os.py invalid due to os.environ.clear() followed by reliance on environ COMSPEC
Luke Kenneth Casson Leighton
report at bugs.python.org
Sun Jan 25 12:39:18 CET 2009
New submission from Luke Kenneth Casson Leighton <lkcl at lkcl.net>:
class EnvironTests(mapping_tests.BasicTestMappingProtocol):
"""check that os.environ object conform to mapping protocol"""
type2test = None
def _reference(self):
return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
def _empty_mapping(self):
vvvvvv
os.environ.clear() <<<<<---------- *******
^^^^^^
return os.environ
def setUp(self):
self.__save = dict(os.environ)
os.environ.clear()
def tearDown(self):
os.environ.clear()
os.environ.update(self.__save)
# Bug 1110478
def test_update2(self):
if os.path.exists("/bin/sh"):
os.environ.update(HELLO="World")
vvvvv
value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
^^^^^ finds os.environ['COMSPEC'] to be empty!
self.assertEquals(value, "World")
this test will obviously fail, see _PyPopenCreateProcess in
posixmodule.c.
if (i = GetEnvironmentVariable("COMSPEC",NULL,0)) {
char *comshell;
}
/* Could be an else here to try cmd.exe / command.com in the path
Now we'll just error out.. */
else {
PyErr_SetString(PyExc_RuntimeError,
"Cannot locate a COMSPEC environment variable to "
"use as the shell");
return FALSE;
}
the environment variables having been destroyed, there _is_ no
COMSPEC to obtain a working cmd.exe or command.com in order to
execute the /bin/sh (or /bin/sh.exe in the case of having installed
msys and created a symlink from c:/msys/bin to c:/bin).
----------
components: Tests
messages: 80502
nosy: lkcl
severity: normal
status: open
title: test_update2 in test_os.py invalid due to os.environ.clear() followed by reliance on environ COMSPEC
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5051>
_______________________________________
More information about the New-bugs-announce
mailing list