github操作pytest失败过程以及将其保存到txt文件

发布于 2025-02-03 14:26:15 字数 336 浏览 2 评论 0原文

我正在尝试设置工作流程,该工作流程运行测试和评论测试覆盖范围。为了实现这一目标,我需要将PYTest调用结果保存到TXT文件中。但是,通过以下命令这样做:

运行pytest -cov =。/ --- junitxml = pytest.xml - capture = tee-sys -cov-report =术语=术语 - 验证术:跳过覆盖的测试/ test_app .py | Tee Pytest-cover.txt

我会遇到一个问题,如果某些测试失败,则整个工作流程都会完成。我想要的是如果任何测试失败,工作流都会失败,否则我将使用pytest-coverage.txt打印代码覆盖范围。

I am trying to set up workflow, which runs tests and comments test coverage. To achieve that, I need to save pytest call results into txt file. However, by doing so with following command:

Run pytest --cov=./ --junitxml=pytest.xml --capture=tee-sys --cov-report=term-missing:skip-covered tests/test_app.py | tee pytest-coverage.txt

I run into a problem, when if some tests fail whole workflow finishes anyway. What I want is workflow failing if any of the tests fail, otherwise I will use pytest-coverage.txt to print code coverage.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2025-02-10 14:26:15

您可能需要设置PipeFail

如果设置,管道的返回值是最后一个(最右)&gt的值;命令以非零状态退出,或者如果在
管道成功退出。此选项默认情况下是禁用的。

因此,工作流步骤应该是:

run: |
  set -o pipefail
  pytest --cov=./ \
         --junitxml=pytest.xml \
         --capture=tee-sys \
         --cov-report=term-missing:skip-covered \
         tests/test_app.py | \
  tee pytest-coverage.txt

注意:

  • 在云跑步者中,这不是必需的,但似乎是发行在自主跑步者中。
  • 另外,也可以通过修改shell作业默认值

You might need to set pipefail:

If set, the return value of a pipeline is the value of the last (rightmost) > command to exit with a non-zero status, or zero if all commands in the
pipeline exit successfully. This option is disabled by default.

So the workflow step should be:

run: |
  set -o pipefail
  pytest --cov=./ \
         --junitxml=pytest.xml \
         --capture=tee-sys \
         --cov-report=term-missing:skip-covered \
         tests/test_app.py | \
  tee pytest-coverage.txt

Notes:

  • In cloud runners this shouldn't be necessary but it seems to be an issue in self-hosted runners.
  • Alternatively it could also be set by modifying shell in job defaults.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文