PyCharm只能单独进行单独测试

时间:2015-05-19 08:55:38

标签: python unit-testing pycharm

我可以通过右键单击它们并选择Run 'Unittests in test_whatever'来单独运行我的测试用例,但是当我右键单击项目根文件夹并选择Run 'Unittests in MyProject'时,我会得到像这样的ImportErrors:

Testing started at 10:42 ...
Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.5\helpers\pycharm\utrunner.py", line 113, in <module>
    modules = loadModulesFromFolderRec(a[0])
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.5\helpers\pycharm\utrunner.py", line 63, in loadModulesFromFolderRec
    os.path.walk(folder, walkModules, (modules, pattern))
  File "C:\Python27\lib\ntpath.py", line 272, in walk
    walk(name, func, arg)
  File "C:\Python27\lib\ntpath.py", line 272, in walk
    walk(name, func, arg)
  File "C:\Python27\lib\ntpath.py", line 272, in walk
    walk(name, func, arg)
  File "C:\Python27\lib\ntpath.py", line 272, in walk
    walk(name, func, arg)
  File "C:\Python27\lib\ntpath.py", line 272, in walk
    walk(name, func, arg)
  File "C:\Python27\lib\ntpath.py", line 272, in walk
    walk(name, func, arg)
  File "C:\Python27\lib\ntpath.py", line 272, in walk
    walk(name, func, arg)
  File "C:\Python27\lib\ntpath.py", line 268, in walk
    func(arg, top, names)
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.5\helpers\pycharm\utrunner.py", line 51, in walkModules
    modules.append(loadSource(os.path.join(dirname, name)))
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.5\helpers\pycharm\utrunner.py", line 40, in loadSource
    module = imp.load_source(moduleName, fileName)
  File "C:\Users\Filip\PycharmProjects\MyProject\venv\lib\python2.7\site-packages\Crypto\SelfTest\Cipher\test_AES.py", line 29, in <module>
    from common import dict     # For compatibility with Python 2.1 and 2.2
ImportError: No module named common

我认为这与工作目录有关。

我正在运行python 2.7.9。是的,virtualenv在项目文件夹中,在git上。不要问。

1 个答案:

答案 0 :(得分:0)

您是否在pyCharm的运行/调试配置对话框中设置了将内容根添加到PYTHONPATH 将源根添加到PYTHONPATH 的复选框。如果没有,这可能有所帮助。