[英]Github pytest Action failing to import from tests/ folder
我有一個 GitHub 操作設置來運行 pytest。 這在大約一個月前有效,但現在突然出現以下錯誤:
==================================== ERRORS ====================================
_____________ ERROR collecting tests/test_encoding/test_encode.py ______________
import file mismatch:
imported module 'test_method' has this __file__ attribute:
/home/runner/work/my_module/my_module/src/my_module/tests/test_package/test_method.py
which is not the same as the test file we want to collect:
/home/runner/work/my_module/my_module/tests/test_package/test_method.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
對於我所有的測試文件,這是一個替換名稱以提高可讀性的示例。
它與我的目錄的放置位置有關,但我不知道為什么它會這樣改變? 出於某種原因,它正在查看我的tests/
文件夾/home/runner/work/my_module/my_module/src/my_module/
而不是/home/runner/work/my_module/qiskit-quantum-knn/
。 我從來沒有在我的項目中添加過src/
文件夾。 我還檢查了我是否不小心提交了__pycache__
或.pytest_cache/
,但事實並非如此。
我將當前日志與幾個月前的日志(成功)進行了比較,並且在作業設置和操作設置期間似乎完全相同。
在我的本地機器上運行pytest
時,它工作得很好。 我的項目結構如下:
my_module
├── docs/
├── my_module
│ ├── package1/
│ ├── package2/
└── tests/
├── test_package1/
│ └── test_method1.py
└── test_package2/
└── test_method2.py
為真正想要深入了解日志的人添加了超鏈接。
它必須與 pip 和 pytest 的版本有關,我的工作流程中沒有固定。 該解決方案是由我的一位好朋友找到的,並已在此pull request中修復。
這意味着將pytest.ini
添加到我的項目的根目錄中,其中包含以下內容:
# pytest.ini
[pytest]
testpaths =
tests
python_files = test_*.py
addopts = -rf --import-mode=importlib
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.