[New-bugs-announce] [issue24247] "unittest discover" does modify sys.path

Sergey Skripnick report at bugs.python.org
Wed May 20 20:11:44 CEST 2015


New submission from Sergey Skripnick:

"unittest discover" does add some directories to sys.path

later some modules can not work with modified sys.path

Here module `pdb` is trying to import standard module `cmd` but does import `cmd` module from `tests` directory:

"unittest discover" should not modify sys.path in any way.

http://dpaste.com/2RYV8E0

$ mkdir /tmp/t
$ cd /tmp/t
$ mkdir tests
$ mkdir tests/cmd
$ touch tests/cmd/__init__.py
$ echo "import pdb" > tests/test_nothing.py
$ python -m unittest discover tests
E
======================================================================
ERROR: test_nothing (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_nothing
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "/tmp/t/tests/test_nothing.py", line 1, in <module>
    import pdb
  File "/usr/lib/python2.7/pdb.py", line 59, in <module>
    class Pdb(bdb.Bdb, cmd.Cmd):
AttributeError: 'module' object has no attribute 'Cmd'


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

----------
messages: 243681
nosy: redixin
priority: normal
severity: normal
status: open
title: "unittest discover" does modify sys.path
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24247>
_______________________________________


More information about the New-bugs-announce mailing list