简体   繁体   English

Travis上的Python子流程覆盖

[英]Python sub-process coverage on Travis

I've seen a couple of articles on the subject, but none seem to work for me.我看过几篇关于这个主题的文章,但似乎没有一篇对我有用。

The case案子

A Python package with tests based on unittest , pytest as test runner and plugins like pytest-cov to support the coverage .一个 Python package 与基于unittest的测试, pytest作为测试运行器和插件,如pytest-cov来支持coverage All works fine locally, all tests are executed and pass, coverage is calculated for all tests, including CLI tests using subprocess.check_output .在本地一切正常,所有测试都执行并通过,计算所有测试的覆盖率,包括使用subprocess.check_output的 CLI 测试。

The issue问题

Somehow, on Travis side, coverage is not calculated for the CLI tests.不知何故,在 Travis 方面,没有为 CLI 测试计算覆盖率。 No matter what I do, no matter where and how many times I do include coverage.pth or sitecustomize.py (read more about it here ), coverage for CLI is not included.无论我做什么,无论我在何处以及多少次包含coverage.pthsitecustomize.py在此处阅读有关它的更多信息),都不包括CLI 的覆盖范围。

The obvious question显而易见的问题

What am I doing wrong?我究竟做错了什么?

As a recap of what was done to solve it (for the folks that may need the answer) the issue was on my configuration of tox to blame.作为对解决它所做的工作的回顾(对于可能需要答案的人),问题在于我的tox配置。

Before (did not work well, although tests passed)之前(虽然测试通过,但效果不佳)

[testenv]
# Some other config above this line
commands =
    pytest

After (where I got it really to the 100% covered)之后(我真正做到了 100% 覆盖)

[testenv]
# Some other config above this line
commands =
    coverage erase
    pip install -e .
    pytest

The pip install -e. pip install -e. is obviously the key here.显然是这里的关键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM