[英]pytest: import file mismatch with added __init__.py files to test directories
有項目目錄,如:
/beta
/task one
__init__.py
test_solution.py
/task two
__init__.py
test_solution.py
當嘗試通過python3 -m pytest --collect-only
收集測試時,出現錯誤:
import file mismatch:
imported module 'test_solution' has this __file__ attribute:
/Applications/PyCharm
CE.app/Contents/bin/https:/github.com/vmred/untitled/beta/task one/test_solution.py
which is not the same as the test file we want to collect:
/Applications/PyCharm
CE.app/Contents/bin/https:/github.com/vmred/untitled/beta/task
two/test_solution.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
__pycache__
清除了幾次,但沒有得到解決。
可能是什么問題? 還嘗試將python_classes=test_solution.py
添加到pytest.ini
,但也沒有幫助。
當我的目錄名稱包含連字符時,我遇到了同樣的錯誤。 例如:
/beta
/task-one
__init__.py
test_solution.py
/task-two
__init__.py
test_solution.py
將連字符轉換為下划線解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.