在 AWS Codepipeline 中使用 pytest 时导入文件不匹配
Import file mismatch when using pytest in AWS Codepipeline
在 运行 执行命令 coverage run -m pytest -rap --junitxml coverage.xml
后,所有单元和集成测试在我的本地计算机上均成功。但是当我尝试 运行 AWS Codepipeline 中的测试时 returns 出现以下错误:
==================================== ERRORS ====================================
______ ERROR collecting tests/integration_tests/base_integration_test.py _______
import file mismatch:
imported module 'tests.integration_tests.base_integration_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/integration_tests/base_integration_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/integration_tests/base_integration_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_____ ERROR collecting tests/integration_tests/gitlab_integration_test.py ______
import file mismatch:
imported module 'tests.integration_tests.gitlab_integration_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/integration_tests/gitlab_integration_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/integration_tests/gitlab_integration_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
___ ERROR collecting tests/integration_tests/kubernetes_integration_test.py ____
import file mismatch:
imported module 'tests.integration_tests.kubernetes_integration_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/integration_tests/kubernetes_integration_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/integration_tests/kubernetes_integration_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
________________ ERROR collecting tests/unit_tests/base_test.py ________________
import file mismatch:
imported module 'tests.unit_tests.base_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/base_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/base_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
________________ ERROR collecting tests/unit_tests/bot_test.py _________________
import file mismatch:
imported module 'tests.unit_tests.bot_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/bot_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/bot_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_______________ ERROR collecting tests/unit_tests/gitlab_test.py _______________
import file mismatch:
imported module 'tests.unit_tests.gitlab_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/gitlab_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/gitlab_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_________ ERROR collecting tests/unit_tests/kubernetes_service_test.py _________
import file mismatch:
imported module 'tests.unit_tests.kubernetes_service_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/kubernetes_service_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/kubernetes_service_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_____________ ERROR collecting tests/unit_tests/kubernetes_test.py _____________
import file mismatch:
imported module 'tests.unit_tests.kubernetes_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/kubernetes_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/kubernetes_test.py
我已经在测试包中添加了 init 文件。也试过在本地删除 pycache 目录,但没有成功。有人有想法吗?
我的结构是这样的:
通过添加 pytest.ini
文件解决了该问题。有关详细信息,请参阅 。
在 运行 执行命令 coverage run -m pytest -rap --junitxml coverage.xml
后,所有单元和集成测试在我的本地计算机上均成功。但是当我尝试 运行 AWS Codepipeline 中的测试时 returns 出现以下错误:
==================================== ERRORS ====================================
______ ERROR collecting tests/integration_tests/base_integration_test.py _______
import file mismatch:
imported module 'tests.integration_tests.base_integration_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/integration_tests/base_integration_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/integration_tests/base_integration_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_____ ERROR collecting tests/integration_tests/gitlab_integration_test.py ______
import file mismatch:
imported module 'tests.integration_tests.gitlab_integration_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/integration_tests/gitlab_integration_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/integration_tests/gitlab_integration_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
___ ERROR collecting tests/integration_tests/kubernetes_integration_test.py ____
import file mismatch:
imported module 'tests.integration_tests.kubernetes_integration_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/integration_tests/kubernetes_integration_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/integration_tests/kubernetes_integration_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
________________ ERROR collecting tests/unit_tests/base_test.py ________________
import file mismatch:
imported module 'tests.unit_tests.base_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/base_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/base_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
________________ ERROR collecting tests/unit_tests/bot_test.py _________________
import file mismatch:
imported module 'tests.unit_tests.bot_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/bot_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/bot_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_______________ ERROR collecting tests/unit_tests/gitlab_test.py _______________
import file mismatch:
imported module 'tests.unit_tests.gitlab_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/gitlab_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/gitlab_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_________ ERROR collecting tests/unit_tests/kubernetes_service_test.py _________
import file mismatch:
imported module 'tests.unit_tests.kubernetes_service_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/kubernetes_service_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/kubernetes_service_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
_____________ ERROR collecting tests/unit_tests/kubernetes_test.py _____________
import file mismatch:
imported module 'tests.unit_tests.kubernetes_test' has this __file__ attribute:
/codebuild/output/src581058806/src/pyhelper/tests/unit_tests/kubernetes_test.py
which is not the same as the test file we want to collect:
/codebuild/output/src581058806/src/tests/unit_tests/kubernetes_test.py
我已经在测试包中添加了 init 文件。也试过在本地删除 pycache 目录,但没有成功。有人有想法吗?
我的结构是这样的:
通过添加 pytest.ini
文件解决了该问题。有关详细信息,请参阅