如何获取测试覆盖率报告?
How to get report for test coverage?
我有一个这样的 buildspec
文件:
version: 0.2
phases:
install:
commands:
- pip install pytest
- pip install pytest-cov
- pip install .
build:
commands:
- python -m pytest --junitxml=unittests.xml
reports:
unit_tests:
files:
- unittests.xml
file-format: JUNITXML
构建成功,我可以按预期在 Report groups
下查看我的报告。
现在我想扩展它并使用选项 --cov-report
查看覆盖范围。我试过了
version: 0.2
phases:
install:
commands:
- pip install pytest
- pip install pytest-cov
- pip install .
build:
commands:
- python -m pytest --junitxml=unittests.xml --cov-report=xml:coverage.xml
reports:
unit_tests:
files:
- unittests.xml
file-format: JUNITXML
coverage_tests:
files:
- coverage.xml
file-format: COBERTURAXML
但没有成功。我得到输出:
generated xml file: /codebuild/output/<removed>/unittests.xml
... <skipped a few lines here>
Report export config is NO_EXPORT, skip exporting reports
Preparing to copy CODE_COVERAGE report coverage_tests
Expanding base directory path: .
Assembling file list
Expanding .
Expanding file paths for base directory .
Assembling file list
Expanding coverage.xml
Skipping invalid file path coverage.xml
No matching report paths found
Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
Phase context status code: Message:
Error in UPLOAD_ARTIFACTS phase: [coverage_tests: [report files not
found in build]]
如何正确创建报告?
正如@TeejayBruno 在评论中指出的那样,我错过了所需的标志。
当我使用时(其余文件不变)
- python -m pytest --junitxml=unittests.xml --cov-report=xml --cov=ronwo --cov-branch
一切如预期。
我有一个这样的 buildspec
文件:
version: 0.2
phases:
install:
commands:
- pip install pytest
- pip install pytest-cov
- pip install .
build:
commands:
- python -m pytest --junitxml=unittests.xml
reports:
unit_tests:
files:
- unittests.xml
file-format: JUNITXML
构建成功,我可以按预期在 Report groups
下查看我的报告。
现在我想扩展它并使用选项 --cov-report
查看覆盖范围。我试过了
version: 0.2
phases:
install:
commands:
- pip install pytest
- pip install pytest-cov
- pip install .
build:
commands:
- python -m pytest --junitxml=unittests.xml --cov-report=xml:coverage.xml
reports:
unit_tests:
files:
- unittests.xml
file-format: JUNITXML
coverage_tests:
files:
- coverage.xml
file-format: COBERTURAXML
但没有成功。我得到输出:
generated xml file: /codebuild/output/<removed>/unittests.xml
... <skipped a few lines here>
Report export config is NO_EXPORT, skip exporting reports
Preparing to copy CODE_COVERAGE report coverage_tests
Expanding base directory path: .
Assembling file list
Expanding .
Expanding file paths for base directory .
Assembling file list
Expanding coverage.xml
Skipping invalid file path coverage.xml
No matching report paths found
Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
Phase context status code: Message:
Error in UPLOAD_ARTIFACTS phase: [coverage_tests: [report files not
found in build]]
如何正确创建报告?
正如@TeejayBruno 在评论中指出的那样,我错过了所需的标志。
当我使用时(其余文件不变)
- python -m pytest --junitxml=unittests.xml --cov-report=xml --cov=ronwo --cov-branch
一切如预期。