February 2022
Intermediate to advanced
274 pages
6h 28m
English
Usually all tests run sequentially. And that’s just what you want if your tests hit a resource that can only be accessed by one client at a time. However, if your tests do not need to access a shared resource, you could speed up test sessions by running multiple tests in parallel. The pytest-xdist plugin allows you to do that. You can specify multiple processors and run many tests in parallel. You can even push off tests onto other machines and use more than one computer.
For example, let’s look at the following simple test:
| | import time |
| | |
| | |
| | def test_something(): |
| | time.sleep(1) |
Running it takes about one second:
| | $ cd /path/to/code/ch14 |
| | $ pytest test_parallel.py |
| | ========================= ... |
Read now
Unlock full access