पायस्टेस्ट में xdist plugin है जो --boxed
विकल्प प्रदान करता है ताकि प्रत्येक परीक्षण को नियंत्रित उपप्रोसेसर में चलाया जा सके। यहाँ एक बुनियादी उदाहरण ::
# content of test_module.py
import pytest
import os
import time
# run test function 50 times with different argument
@pytest.mark.parametrize("arg", range(50))
def test_func(arg):
time.sleep(0.05) # each tests takes a while
if arg % 19 == 0:
os.kill(os.getpid(), 15)
आप के साथ :: इस चलाते हैं है
$ py.test --boxed
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
collecting ... collected 50 items
test_module.py f..................f..................f...........
================================= FAILURES =================================
_______________________________ test_func[0] _______________________________
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[19] _______________________________
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[38] _______________________________
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
=================== 3 failed, 47 passed in 3.41 seconds ====================
आप देखेंगे कि परीक्षण के एक जोड़े के रूप में क्रैश हो लोअर केस f
द्वारा संकेत दिया रिपोर्ट कर रहे हैं और संबंधित विफलता सारांश। तुम भी xdist-प्रदान की साथ में चलाना सुविधा का उपयोग कर सकते हैं अपने परीक्षण ::
$ py.test --boxed -n3
=========================== test session starts ============================
platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev8
plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov
gw0 I/gw1 I/gw2 I
gw0 [50]/gw1 [50]/gw2 [50]
scheduling tests via LoadScheduling
..f...............f..................f............
================================= FAILURES =================================
_______________________________ test_func[0] _______________________________
[gw0] linux2 -- Python 2.7.3 /home/hpk/venv/1/bin/python
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[19] _______________________________
[gw2] linux2 -- Python 2.7.3 /home/hpk/venv/1/bin/python
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
______________________________ test_func[38] _______________________________
[gw2] linux2 -- Python 2.7.3 /home/hpk/venv/1/bin/python
/home/hpk/tmp/doc-exec-420/test_module.py:6: running the test CRASHED with signal 15
=================== 3 failed, 47 passed in 2.03 seconds ====================
सिद्धांत रूप में तेजी लाने के लिए, बस subprocesses अक्सर ही पर्याप्त होता समानांतर वितरण और प्रत्येक परीक्षा के लिए एक बॉक्स्ड प्रक्रिया शुरू करने की भूमि के ऊपर से बचा जाता है। यह वर्तमान में केवल तभी काम करता है जब -n
प्रक्रियाओं की संख्या के मुकाबले केवल कम क्रैशिंग परीक्षण हो क्योंकि मरने वाली परीक्षण प्रक्रिया को पुनरारंभ नहीं किया जाता है। इस सीमा को शायद बहुत अधिक प्रयास किए बिना हटाया जा सकता है। इस बीच आपको सुरक्षित मुक्केबाजी विकल्प का उपयोग करना होगा।
उपयोगी उदाहरणों के लिए धन्यवाद। ऐसा लगता है कि py.test डॉक्टर ने आदेश दिया है। – jjh