Distributed testing (xdist)#

“load” mode#

Distributed testing with dist mode set to “load” will report on the combined coverage of all workers. The workers may be spread out over any number of hosts and each worker may be located anywhere on the file system. Each worker will have its subprocesses measured.

Running distributed testing with dist mode set to load:

pytest --cov=myproj -n 2 tests/

Shows a terminal report:

-------------------- coverage: platform linux2, python 2.6.4-final-0 ---------------------
Name                 Stmts   Miss  Cover
----------------------------------------
myproj/__init__          2      0   100%
myproj/myproj          257     13    94%
myproj/feature4286      94      7    92%
----------------------------------------
TOTAL                  353     20    94%

Again but spread over different hosts and different directories:

pytest --cov=myproj --dist load
        --tx ssh=memedough@host1//chdir=testenv1
        --tx ssh=memedough@host2//chdir=/tmp/testenv2//python=/tmp/env1/bin/python
        --rsyncdir myproj --rsyncdir tests --rsync examples
        tests/

Shows a terminal report:

-------------------- coverage: platform linux2, python 2.6.4-final-0 ---------------------
Name                 Stmts   Miss  Cover
----------------------------------------
myproj/__init__          2      0   100%
myproj/myproj          257     13    94%
myproj/feature4286      94      7    92%
----------------------------------------
TOTAL                  353     20    94%

“each” mode#

Distributed testing with dist mode set to each will report on the combined coverage of all workers. Since each worker is running all tests this allows generating a combined coverage report for multiple environments.

Running distributed testing with dist mode set to each:

pytest --cov=myproj --dist each
        --tx popen//chdir=/tmp/testenv3//python=/usr/local/python27/bin/python
        --tx ssh=memedough@host2//chdir=/tmp/testenv4//python=/tmp/env2/bin/python
        --rsyncdir myproj --rsyncdir tests --rsync examples
        tests/

Shows a terminal report:

---------------------------------------- coverage ----------------------------------------
                          platform linux2, python 2.6.5-final-0
                          platform linux2, python 2.7.0-final-0
Name                 Stmts   Miss  Cover
----------------------------------------
myproj/__init__          2      0   100%
myproj/myproj          257     13    94%
myproj/feature4286      94      7    92%
----------------------------------------
TOTAL                  353     20    94%