簡體   English   中英

pytest:導入文件與添加的 __init__.py 文件不匹配以測試目錄

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM