2013-10-07 10 views
6

मैं अगले परीक्षण संरचना है कहते हैं:Pytest init सेटअप

 
test/ 
    module1/ 
    test1.py 
    module2/ 
    test2.py 
    module3/ 
    test3.py 

कैसे मैं सेटअप कुछ विधि यह सब परीक्षण से पहले केवल एक बार कहा जा सकता है?

उत्तर

9

आप autouse जुड़नार का उपयोग कर सकते हैं:

# content of test/conftest.py 

import pytest 
@pytest.fixture(scope="session", autouse=True) 
def execute_before_any_test(): 
    # your setup code goes here, executed ahead of first test 

अधिक जानकारी के लिए pytest fixture docs देखें।

+2

मैं सिर्फ इस बात पर जोर देना चाहता था कि 'conftest.py' में होना इस समाधान की' वैश्विकता 'का एक महत्वपूर्ण बिंदु है। आपका बहुत बहुत धन्यवाद! – Emmanuel