Possible Duplicate:
Can Python's unittest test in parallel, like nose can?
I have tests that are used with unittest and they are run 1 by 1. I would like to run them in parallel because I have a lot of wait so it would go much faster. Is it possible ? I can't find a solution on the internet eventhough many ppl are talking about it.
unittest-parallel is a parallel unit test runner for Python with coverage support. By default, unittest-parallel runs unit tests on all CPU cores available. To run your unit tests with coverage, add either the "--coverage" option (for line coverage) or the "--coverage-branch" for line and branch coverage.
Enabling parallelization is opt-in. Once it's enabled, you can opt-out for a specific test or class using [DoNotParallelize] . The runner will execute Test2 and Test3 in parallel. Then, it will execute Test1 .
Which is better – pytest or unittest? Although both the frameworks are great for performing testing in python, pytest is easier to work with. The code in pytest is simple, compact, and efficient. For unittest, we will have to import modules, create a class and define the testing functions within that class.
By default, pytest runs tests in sequential order. In a real scenario, a test suite will have a number of test files and each file will have a bunch of tests. This will lead to a large execution time. To overcome this, pytest provides us with an option to run tests in parallel.
You could alternatively parallelize via the shell, no? I just tried this command
find -type f -name "_test_*.py" | sed 's/^\.\///; s/\.py$//; s/\//./g;' | xargs -t -P 10 -n 2 python -m unittest
The find
outputs a list of test files, so adapt the filename pattern to your naming convention. The sed
transforms the found paths to valid module names. The xargs
starts, in this example, up to 10 processes each running 2 test modules.
I'm not sure yet how to make sense of the output ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With