我在包中有一個文件名中帶有“test”,當我運行 pytest 時出現錯誤import file mismatch:imported module 'my_project.my_file_test' has this __file__ attribute: /my_project/src/my_project/build/lib/python2.7/site-packages/foo/my_file_test.pywhich is not the same as the test file we want to collect: /my_project/src/my_project/build/private/python2.7/lib/foo/my_file_test.pyHINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules如果我從文件中刪除“測試”,它可以正常工作,但不幸的是我無法更改它。所以問題是如何告訴pytest忽略這個文件?
3 回答

慕萊塢森
TA貢獻1810條經驗 獲得超4個贊
所以最后很容易,我只需要在pytest.ini
文件中添加測試文件模式
python_files = test_*.py
所以 pytest 停止尋找test
名稱末尾的文件,默認情況下它所做的。
添加回答
舉報
0/150
提交
取消