-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tox: guard against parallel pytest coverage execution #15
Conversation
The tox docs are only mention "incomplete coverage", but in practice it's possible to trigger test errors. I've observed the following without these changes:
|
ea4e5bc
to
a377a7c
Compare
An usual problem users have is that pytest-cov will erase the previous coverage data by default, thus if you run tox with multiple environments you’ll get incomplete coverage at the end. To prevent this problem you need to use --cov-append. It’s still recommended to clean the previous coverage data to have consistent output. Cf. https://pytest-cov.readthedocs.io/en/latest/tox.html
pytest-cov has issues when run in parallel when using coverage 5, as noted by the pytest-cov authors. Use coverage 4 until pytest-cov is ready for coverage 5, or a better solution is documented. pytest-dev/pytest-cov@d3daf76 pytest-dev/pytest-cov#386
a377a7c
to
1419f51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. I'd very much like to support evaluating coverage across runs of different Python. I've historically suppressed or ignored coverage on files that had selective execution.
I have some reservations, but I'm happy to explore options.
@@ -1,5 +1,5 @@ | |||
[tox] | |||
envlist = python | |||
envlist = clean,python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My biggest reservation comes from this change, which
(a) adds an extra tox environment to the default argument,
(b) doesn't run under explicit environment invocations such as 'tox -e py38' or 'tox -e python' (which I have configured in my environment),
(c) corrects for lingering state at the beginning, and
(d) even with all of this, the coverage details aren't going to be readily appended in CI environments or other environments that provide isolation between runs.
I think I'd prefer to keep a simple 'tox' environment to simply run the tests, but add more complicated configurations to wrapper scripts or CI invocations or user-local settings.
Do you have a place where you're already using this approach? Does coverage recommend this approach?
@@ -14,9 +14,17 @@ deps = | |||
pip_version = pip | |||
commands = | |||
pytest {posargs} | |||
depends = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this feature was added in tox 3.7, so that would imply a minversion bump to 3.7.
@@ -23,6 +23,7 @@ setup_requires = setuptools_scm[toml] >= 3.4.1 | |||
[options.extras_require] | |||
testing = | |||
# upstream | |||
coverage < 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd prefer this to appear at the end of the list - that's where I typically add them.
@@ -23,6 +23,7 @@ setup_requires = setuptools_scm[toml] >= 3.4.1 | |||
[options.extras_require] | |||
testing = | |||
# upstream | |||
coverage < 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More importantly, what's this line about? Is it to add coverage? To limit coverage? I do try to avoid pinning dependencies without a reason to pin (and a comment to explain why). Looking quickly at coverage, this is a downgrade from what's currently used. Is it necessary to support this feature? If so, there should be a comment explaining that.
@@ -1,5 +1,6 @@ | |||
[run] | |||
omit = .tox/* | |||
parallel = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change generally applicable?
c4e3b4d
to
fc0162b
Compare
Thanks for the review notes. I agree, this isn't ready yet. The That said, the recent pytest release notes mention changes that may have already addressed these issues, so it's worth trying newer versions these days. https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst#290-2020-05-22 As you noted, this would be best mentioned in a code comment in addition to the commit message so that it doesn't get lost in this random github thread. I have to revisit the
In order to provide a simple tox test environment where users won't stumble into these edge cases then what do you think about this?
The most useful feature for me is parallel tox running of tests; coverage is secondary and not as important in my perspective, but 1. does not shut the door to that use case. Supporting all the various test dependency permutations with parallel tox running and coverage can be tricky, which is why it seems like punting and making them explicit separate steps seems helpful. Of course, this is something that would be best documented a bit, so perhaps the best first commit/patch would be to come up with a patch against What do you think? |
58cca73
to
1311cec
Compare
An usual problem users have is that pytest-cov will erase the
previous coverage data by default, thus if you run tox with
multiple environments you’ll get incomplete coverage at the end.
To prevent this problem you need to use --cov-append. It’s still
recommended to clean the previous coverage data to have
consistent output.
Cf. https://pytest-cov.readthedocs.io/en/latest/tox.html