简体   繁体   English

PyCharm单元测试只能单独使用

[英]PyCharm unittests only work individually

I can run my test cases individually by right-clicking them and selecting Run 'Unittests in test_whatever' but when I right-click the project root folder and select Run 'Unittests in MyProject' I get ImportErrors such as this: 我可以通过右键单击Run 'Unittests in test_whatever'然后选择Run 'Unittests in test_whatever'来分别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

I'm assuming this has something to do with the working directory. 我假设这与工作目录有关。

I'm running python 2.7.9. 我正在运行python 2.7.9。 And yes, the virtualenv is in the project folder, and on git. 是的,virtualenv在项目文件夹中,在git上。 Don't ask. 不要问

Did you set the checkboxes Add content roots to PYTHONPATH and Add source roots to PYTHONPATH in the Run/Debug Configuration Dialog of pyCharm. 您是否在pyCharm的“运行/调试配置”对话框中选中了“ 将内容根添加到PYTHONPATH”和“ 将源根添加到PYTHONPATH 复选框。 If not, this could help. 如果没有,这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM