[英]Can't debug unittests in Pycharm
我在 pycharm 中調試單元測試時遇到問題。 我可以用我的配置運行它們,但是當我運行調試器時,我得到以下錯誤輸出:
Error 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: Failed to import test module: 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] No such file or directory: 'pydevd_attach_to_process'
我的目錄結構是:
我的單元測試配置是:
tests/test_setup_script.py
看起來像:
import unittest import os import setup # the path to this file is scheduler/setup.py. This import may be breaking things class TestSetupScript(unittest.TestCase): def test_load_db_connection_valid_yaml_file(self): file_name = "valid-yaml.yml" with open(file_name, 'w') as file: file.write(""" test: hello world a = b """) yaml = setup.load_yaml_configuration(file_name) # I want to debug the line above, hence no assertions here
pydevd_attach_to_process
什么作用,如何確保在調試過程中找到它? 問題實際上與找到的文件/目錄無關嗎?
實際上,發生故障是因為代碼中的“導入設置”導入了設置模塊,該模塊是 PyCharm 調試器運行時的一部分,而不是您自己的設置模塊。 最簡單的解決方法是將 setup.py 文件重命名為其他名稱,並相應地更新代碼中的導入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.