使用命令python -m pytest tests
运行完整测试时,导入文件不匹配错误将失败。
import file mismatch:
imported module 'test_simplifyvcf_integrations' has this __file__ attribute:
/home/promechpc5/Desktop/VCF-SimplifyDev/tests/test_integrations/test_simplifyvcf_integrations.py
which is not the same as the test file we want to collect:
/home/promechpc5/Desktop/VCF-SimplifyDev/tests/testfiles/TestFullApp/test_simplifyvcf_integrations.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
在这里,错误显示为test_simplifyvcf_integration.py,它位于“测试”文件夹下。但是当我用命令python -m pytest tests/test_integrations/test_simplifyvcf_integrations.py
单独运行测试时,它通过了所有的测试。
发布于 2019-12-22 18:11:16
这里的解决方案出现在错误消息中:
和/或为您的测试文件模块使用唯一的basename
您必须确保测试中有唯一的模块名-- pytest会将它们全部提升到顶级命名空间中,除非您添加__init__.py
文件,使它们成为不同的包。
所以你的选择是:
__init__.py
文件发布于 2019-12-22 14:25:04
这是一个与pytest特别相关的问题,所以您不必太担心,因为它只与缓存的文件有关。
步骤1从测试目录中删除所有__pycache__
文件夹。
步骤2根据停止生成这些缓存的步骤,在bashrc/zshrc文件中添加以下代码段。
export PYTHONDONTWRITEBYTECODE=1
https://stackoverflow.com/questions/59444982
复制相似问题