pytest 執行報錯:HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
阿新 • • 發佈:2021-06-22
同事將她的專案檔案發給我,我在執行時報錯如下:
import file mismatch: imported module 'tests.desktop.consumer_pages.test_details_page' has this __file__ attribute: /Users/chen/gitRepos/marketplace-tests/tests/desktop/consumer_pages/test_details_page.py which is not the same as the test file we want to collect: /Users/xhong/Documents/gitRepos/marketplace-tests/tests/desktop/consumer_pages/test_details_page.py HINT: remove__pycache__ / .pyc files and/or use a unique basename for your test file modules
這是 Python.pyc
在編譯程式碼時在我的機器上建立檔案這一事實的徵兆。這也可能導致其他問題,以及弄亂你的機器,所以我想刪除所有這些檔案,並防止 Python 將來這樣做。這篇文章包含有關如何做到這兩點的資訊。
解決方法:
從資料夾中刪除所有 .pyc 檔案
您可以使用該find
命令(在 OS X 和 Linux 上)定位所有.pyc
檔案,然後使用其delete
選項刪除它們。
.pyc
從當前資料夾開始查詢所有資料夾中所有檔案的命令是:
find . -name '*.pyc'
如果要刪除找到的所有檔案,只需新增-delete
選項:
find . -name '*.pyc' -delete
顯然,這可以用於您希望根除的任何檔案型別,而不僅僅是.pyc
檔案。
再次執行,問題解決。