2011-01-09 10 views
18

Ho la seguente struttura delle directory:C'è un modo per controllare come pytest-xdist esegue test in parallelo?

runner.py 
lib/ 
tests/ 
     testsuite1/ 
       testsuite1.py 
     testsuite2/ 
       testsuite2.py 
     testsuite3/ 
       testsuite3.py 
     testsuite4/ 
       testsuite4.py 

Il formato della testsuite * moduli .py è la seguente:

 
import pytest 
class testsomething: 
     def setup_class(self): 
      ''' do some setup ''' 
      # Do some setup stuff here  
     def teardown_class(self): 
      '''' do some teardown''' 
      # Do some teardown stuff here 

     def test1(self): 
      # Do some test1 related stuff 

     def test2(self): 
      # Do some test2 related stuff 

     .... 
     .... 
     .... 
     def test40(self): 
      # Do some test40 related stuff 

if __name__=='__main()__' 
    pytest.main(args=[os.path.abspath(__file__)]) 

Il problema che ho è che vorrei eseguire le suite di test '' in parallelo, cioè voglio testuite1, testsuite2, testsuite3 e testsuite4 per avviare l'esecuzione in parallelo, ma i singoli test all'interno dei test devono essere eseguiti in serie.

Quando uso il plugin 'xdist' da py.test e avvia i test usando 'py.test -n 4', py.test sta raccogliendo tutti i test e carica in modo casuale i test tra 4 lavoratori. Questo porta al metodo 'setup_class' che deve essere eseguito ogni volta di ogni test all'interno di un modulo 'testsuitex.py' (che sconfigge il mio scopo. Voglio setup_class da eseguire solo una volta per classe e test eseguiti in serie lì dopo).

In sostanza quello che voglio l'esecuzione a guardare come è:

 
worker1: executes all tests in testsuite1.py serially 
worker2: executes all tests in testsuite2.py serially 
worker3: executes all tests in testsuite3.py serially 
worker4: executes all tests in testsuite4.py serially 

mentre worker1, worker2, worker3 and worker4 sono tutti eseguiti in parallelo.

Esiste un modo per ottenere questo risultato nel framework "pytest-xidst"?

L'unica opzione che mi viene in mente è quello di dare il via diversi processi per eseguire ogni suite di test singolarmente entro runner.py:

 

def test_execute_func(testsuite_path): 
    subprocess.process('py.test %s' % testsuite_path) 

if __name__=='__main__': 
    #Gather all the testsuite names 
    for each testsuite: 
     multiprocessing.Process(test_execute_func,(testsuite_path,)) 

risposta

11

Con pytest-xdist non ci attualmente nessun tipo di "per-file" o distribuzione "per-test-suite". In realtà, se una distribuzione per file (ad esempio test in un file verrà eseguita solo al massimo un lavoratore alla volta) sarebbe già di aiuto per il tuo caso di utilizzo ti incoraggio a presentare un problema con il tracker di problemi pytest al numero https://bitbucket.org/hpk42/pytest/issues?status=new&status=open e link torna alla tua buona spiegazione qui.

applausi Holger

+5

Per chiunque la visualizzazione di questo post e si chiede se sono stati aperti tutti i problemi, i problemi sono: https://github.com/pytest-dev/pytest/issues/175 e https: // github.com/pytest-dev/pytest/issues/738 –

+4

E questo: https://github.com/pytest-dev/pytest-xdist/issues/7 –

Problemi correlati