分散測試(xdist)

“load” 模式

使用將 dist 模式設定為 “load” 的分散測試會報告所有工作者的合併涵蓋率。這些工作者可以分散在任意數量的主機上,且每個工作者可以在檔案系統中的任何位置。每個工作者的子程序都會經過測量。

使用將 dist 模式設定為 load 的分散測試

pytest --cov=myproj -n 2 tests/

顯示終端機報告

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

再次在不同的主機和目錄中分散

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/

顯示終端機報告

-------------------- 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”模式

使用將 dist 模式設定為 each 的分散測試會報告所有工作者的合併涵蓋率。由於每個工作者都在執行所有測試,所以這允許產生多個環境的合併涵蓋率報告。

使用將 dist 模式設定為 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/

顯示終端機報告

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