2013-10-07 17 views
6

i sonraki testler yapıya sahip ki:Pytest init kurulum

i kurulum bazı yöntemi tüm bu testlerden önce yalnızca bir kez çağrılacak nasıl
 
test/ 
    module1/ 
    test1.py 
    module2/ 
    test2.py 
    module3/ 
    test3.py 

?

cevap

9

Sen autouse demirbaşlar kullanabilirsiniz:

# 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 

fazla bilgi için pytest fixture docs bakınız.

+2

Sadece bir 'conftest.py' içinde olmanın bu çözümün 'globalitesine' kilit bir nokta olduğunu vurgulamak istedim. Çok teşekkürler! – Emmanuel