在Pycharm中无法调试单元测试

7

我在pycharm中调试单元测试时遇到了问题。我可以使用我的配置正常运行它们,但是当我运行调试器时,我会得到以下错误输出:

错误
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 34, in testFailure
    raise self._exception
ImportError: 导入测试模块失败:tests
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 462, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
  File "/Users/paymahn/solvvy/scheduler/tests/__init__.py", line 2, in 
    import tests.test_setup_script
  File "/Users/paymahn/solvvy/scheduler/tests/test_setup_script.py", line 3, in 
    import setup
  File "/Applications/PyCharm.app/Contents/helpers/pydev/setup.py", line 87, in 
    data_files.append(('pydevd_attach_to_process', [os.path.join('pydevd_attach_to_process', f) for f in os.listdir('pydevd_attach_to_process') if accept_file(f)]))
FileNotFoundError: [Errno 2] 没有这样的文件或目录:'pydevd_attach_to_process'

我的目录结构如下:

enter image description here

我的unittest配置如下:

enter image description here

tests/test_setup_script.py 的代码如下:

导入unittest和os模块,以及setup.py文件的路径。在运行测试用例时,调用load_yaml_configuration函数并传递valid-yaml.yml文件名作为参数。该函数将读取文件并返回YAML格式的配置数据。没有断言,因为想要调试上面的代码。

pydevd_attach_to_process是什么?如何确保在调试过程中找到它?问题实际上与文件/目录是否被找到无关吗?


也许尝试安装/重新安装 'pydevd'?文件->设置->项目:....->项目解释器->'+'->pydevd->安装包 - nanotek
1个回答

5

实际上,失败是因为您的代码中的“import setup”导入了PyCharm调试器运行时的一部分——即setup模块,而不是您自己的setup模块。最简单的解决方法是将您的setup.py文件重命名为其他名称,并相应地更新代码中的导入。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接