【问题标题】:Import file mismatch when using pytest in AWS Codepipeline在 AWS Codepipeline 中使用 pytest 时导入文件不匹配
【发布时间】:2022-01-12 18:25:30
【问题描述】:

运行命令coverage run -m pytest -rap --junitxml coverage.xml 后,所有单元和集成测试都在我的本地机器上成功。但是当我尝试在 AWS Codepipeline 中运行测试时,它会返回以下错误:

==================================== 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 目录,但没有成功。有人出主意吗?

我的结构是这样的:

【问题讨论】:

    标签: unit-testing pytest integration-testing aws-codepipeline mismatch


    【解决方案1】:

    通过添加pytest.ini 文件解决了这个问题。详情请见this answer

    【讨论】:

      猜你喜欢
      • 2017-05-28
      • 1970-01-01
      • 2019-06-28
      • 2021-10-22
      • 2021-07-23
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多