gpt4 book ai didi

python - pytest运行complete test出现import file mismatch错误,单独运行通过test

转载 作者:行者123 更新时间:2023-12-04 16:45:25 38 4
gpt4 key购买 nike

当使用命令 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,在tests文件夹下。但是当我使用命令 python -m pytest tests/test_integrations/test_simplifyvcf_integrations.py 单独运行测试时,它通过了所有测试。

最佳答案

这里的解决方法在报错信息中:

and/or use a unique basename for your test file modules

您必须确保您的测试中有唯一的模块名称——pytest 会将它们全部提升到顶级命名空间除非您添加 __init__.py 文件,例如它们是不同的包

所以你的选择是:

  • 重命名相同的文件
  • 添加一些__init__.py文件

关于python - pytest运行complete test出现import file mismatch错误,单独运行通过test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59444982/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com