Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unittest in parallel [duplicate]

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.

like image 893
swan Avatar asked Nov 15 '11 08:11

swan


People also ask

Does Unittest run tests in parallel?

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.

How do I run Mstest in parallel?

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?

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.

Does Pytest run tests in parallel?

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.


1 Answers

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 ...

like image 137
wutz Avatar answered Oct 20 '22 00:10

wutz