简体   繁体   中英

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:

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. And yes, the virtualenv is in the project folder, and on 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. If not, this could help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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