pytest 运行报错:HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

同事将她的项目文件发给我,我在运行时报错如下:

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文件。

再次运行,问题解决。

原文地址:https://www.cnblogs.com/xiehong/p/14917682.html