使用 pytest 设置测试报告 - Amazon CodeBuild
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 pytest 设置测试报告

以下过程演示如何在 Amazon CodeBuild 中使用 pytest 测试框架来设置测试报告。

该过程需要以下先决条件:

  • 您有一个现有的 CodeBuild 项目。

  • 您的项目是一个 Python 项目,此项目设置为使用 pytest 测试框架。

将以下条目添加到 buildspec.yml 文件的 buildpost_build 阶段。此代码会自动发现当前目录中的测试,并将测试报告导出到由 <测试报告目录>/<报告文件名> 指定的文件中。报告使用 JunitXml 格式。

- python -m pytest --junitxml=<test report directory>/<report filename>

在您的 buildspec.yml 文件中,添加/更新以下部分。

version: 0.2 phases: install: runtime-versions: python: 3.7 commands: - pip3 install pytest build: commands: - python -m pytest --junitxml=<test report directory>/<report filename> reports: pytest_reports: files: - <report filename> base-directory: <test report directory> file-format: JUNITXML