2011-10-17 3 views
13

Come posso ottenere al momento in esecuzione nome testcase, mentre nella raccolta di testuite ci sono 16 testicoli. I test vengono eseguiti in sequenza (nell'ordine di aggiunta del test alla raccolta testSuite). Quando aggiungo tutti i test alla collezione testSuite, posso visualizzare l'anteprima di questo oggetto, ma come posso eseguire il test in esecuzione mentre i test sono in esecuzione. Forse alcune variabili contengono queste informazioni?Come eseguire il nome della testcase in esecuzione da testsuite nell'unità di prova

esempio:

def suite(): 
    testSuite= unittest.TestSuite() 
    testSuite.addTest(FlightsTestCases('test_sel__reservation_one_way_wizzair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_round_wizzair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_round_tair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_credit_card')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_credit_card')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_round_wizzair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_wizzair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_easyjet_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_ryanair_transfer')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_round_ryanair_credit_card')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_duplicated')) 
    testSuite.addTest(FlightsTestCases('test_reservation_wrong_card_lowcost')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_credit_card')) 
    testSuite.addTest(FlightsTestCases('test_sel_reservation_one_way_tair_wrong_credit_card')) 

    return testSuite 

if __name__ == "__main__": 
    result = unittest.TextTestRunner(verbosity=2).run(suite()) 
    sys.exit(not result.wasSuccessful()) 

I test vengono eseguiti utilizzando framework Selenio-RC.

+1

Qual è il contesto in cui si desidera eseguire la query per il nome del test in esecuzione? –

risposta

38

unittest.TestCase.shortDescription()

Restituisce una descrizione del test, o None se nessuna descrizione è stata fornita. L'implementazione predefinita di questo metodo restituisce la prima riga della docstring del metodo di prova, se disponibile, o None.

unittest.TestCase.id()

ritorno una stringa che identifica il caso specifico test. Di solito questo è il nome completo del metodo di test, incluso il modulo e il nome della classe.

Speriamo che uno di questi sia utile per le vostre esigenze.

Problemi correlati