-
-
Notifications
You must be signed in to change notification settings - Fork 442
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
Tests: Speed up test suite by invoking tests in parallel, using pytest-xdist
#690
Conversation
5a2188e
to
3adcb41
Compare
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #690 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 113 113
Lines 14533 14533
Branches 2787 2787
=========================================
Hits 14533 14533 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
d3ec373
to
8bcc6e1
Compare
8bcc6e1
to
7ca2b42
Compare
So you dropped code coverage completely with this? |
7ca2b42
to
337db20
Compare
337db20
to
94cad72
Compare
I've just started a new build in order to keep the reference to the failure with build #585326200 1. It succeeded. Footnotes |
94cad72
to
f475704
Compare
This happens ALL the time; every now and then a random test that never failed (ever) in the past just fails on TravisCI. It's usually always related to the Attachments. But giving the CI a kick again always has it work the second time around. So no worries at all here; at this point it's more of nuisance then anything; it just doesn't happen enough for me to investigate it further at this time. I can't tell if it's a Travis-CI issue, or the way my tests are written, or if if it's some mulch-threading issue with Apprise and the timing of some of the attachment tests (causing it to pass 99.9% of the time). If it happens again, even if I'm not in front of my PC, i can give easily give Travis CI runner a kick. Feel free to just ask me to do so... (or do a force-push on the branch again; that'll trigger it to go again too). 🤷♂️ |
I really appreciate your efforts here, but i don't want to drop code coverage. I personally don't think the 2 min of resource time gained is worth not knowing the coverage on every commit pushed upstream. |
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.
Hi again,
So you dropped code coverage completely with this?
I really appreciate your efforts here, but i don't want to drop code coverage.
I totally agree with you, code coverage tracking and reporting is very important, it must not go away. Thus, I would never dare to remove it ;]. I think there only was a small hiccup at the time when you looked at the outcome here, which has now been fixed.
Other than diligently going through each line of the configuration changes within the review comments, let me explain the situation.
With 1e2d155 and 8bcc6e1, I tried to bring improved efficiency to both the developer sandbox and CI. However, the changes had to be reverted, because I haven't been able to make it work on CI together with coverage tracking.
I think the reason are some shenanigans related to tox
, where I didn't have the energy to find out about the root cause.
So, this patch just adds the foundation, and might set the stage for bringing it to CI later. However, it already brings improved efficiency to the developer's sandbox, as you will be able to run the test suite in half of the time as before.
Both of those commands will work as intended, as announced in the original post.
To use it, invoke:
pytest -vvv --numprocesses=auto
To use it with coverage tracking and reporting, invoke:
pytest -vvv --numprocesses=auto --cov
Please note it is a must to use pytest-cov
, running the process through the coverage
program does not work here.
With kind regards,
Andreas.
@@ -2,5 +2,6 @@ coverage | |||
flake8 | |||
pytest | |||
pytest-cov | |||
pytest-xdist |
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.
This line only adds the pytest-xdist
package to the list of dependencies.
branch = True | ||
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.
Using this option is obligatory for running tests in parallel. It will create many files like .coverage.{hostname}.23098.826306
, which will be combined by coverage combine
later. Following up on this, I think using the --parallel
option within tox.ini
can be removed.
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 think using the
--parallel
option withintox.ini
can be removed.
Implemented with 290ffc1.
@@ -1,6 +1,7 @@ | |||
[run] | |||
disable_warnings = no-data-collected | |||
data_file = .coverage-reports/.coverage |
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.
Because many files like .coverage.{hostname}.23098.826306
will be created, I don't want to make them appear in the root directory. It is better to materialize them inside a dedicated subdirectory, which can easily be made excluded from being indexed by your favorite IDE.
With this setting, the files will be materialized like .coverage-reports/.coverage.{hostname}.23098.826306
.
@@ -131,4 +131,5 @@ deps = coverage | |||
skip_install = true | |||
commands= | |||
coverage combine | |||
coverage xml |
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.
This is needed to write out a coverage.xml
file to the root directory. The reason is that the combined .coverage-reports/.coverage
file can't be picked up by the codecov
program because of codecov/codecov-python#198. However, it fortunately does pickup coverage.xml
instead.
@@ -1,6 +1,7 @@ | |||
[run] | |||
disable_warnings = no-data-collected |
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.
Last but not least, the commit f475704 removes this line. A rationale is provided in its commit message.
It was important to discover that running the tests with
pytest-xdist
on Travis CI did not produce any coverage reports at all. This setting disabled that warning, so we didn't see it, which was unfortunate.
This is amazing; i didn't realize the small changes needed at the end. Do we need anything in the You are awesome Andreas! 🚀 ❤️ |
Your attention to detail is amazing. I also expected that we need another item, but apparently, the item |
Re. #690 (comment):
Thanks a stack for sharing your observations. Let us work diligently here, so I created #692. |
pytest-xdist
It uses the excellent `pytest-xdist` package. To use it, invoke: pytest -vvv --numprocesses=auto To use it with coverage tracking and reporting, invoke: pytest -vvv --numprocesses=auto --cov --cov-report=term-missing
It was important to discover that running the tests with `pytest-xdist` on Travis CI did not produce any coverage reports at all. This setting disabled that warning, which was unfortunate.
It is now already defined within `.coveragerc`.
290ffc1
to
0b5b99a
Compare
8b8587e
to
6b02e73
Compare
By using the excellent
pytest-xdist
package, I was able to reduce the runtime of the test suite from 45 to 15 (no coverage) / 25 (with coverage) seconds, tested on machines with 8 and 16 CPUs.It apparently also improves runtime on Travis CI, so it would be a big resource saver.
Running the tests in parallel also ensures there are no spots where shared resources are not properly accessed in concurrent situations. It will reveal such shortcomings very quickly.