2015-01-17 10 views

risposta

9

installazione

  1. Installare il Atom editor di
  2. Installare il pacchetto Script in questo modo:

    a) Avviare Atom

    b) Premere Ctrl + Maiusc + P, digitare "installare i pacchetti e le tematiche" e premere Invio per aprire la vista del pacchetto

    c) La ricerca di "script" e installare il pacchetto

Unità esempio test test .py

  1. Scrivi una prova di unità e salvarlo come test.py.

    import unittest 
    
    class MyTest(unittest.TestCase): 
    
        def test_pass(self): 
         pass 
    
        def test_fail(self): 
         call_method_that_does_not_exist() 
    
    if __name__ == '__main__': 
    unittest.main() 
    

unit test Run

  1. Ora, premere Ctrl+I per eseguire lo script Python (see documentation)

uscita Console

Poiché il test di unità test_fail fallirà, questo sarà l'output della console:

E. 
====================================================================== 
ERROR: test_fail (__main__.MyTest) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/Users/Lernkurve/Desktop/PythonDemos/a.py", line 9, in test_fail 
    call_method_that_does_not_exist() 
NameError: global name 'call_method_that_does_not_exist' is not defined 

---------------------------------------------------------------------- 
Ran 2 tests in 0.000s 

FAILED (errors=1) 
[Finished in 0.047s] 
+0

Funziona alla grande! Lo uso con pytest, quindi ho aggiunto il codice per avviare l'esecuzione di test: 'if __name __ == '__main__': pytest.main ([__ file__, '--color = yes'])' – Jonatan

1

è possibile utilizzare il plug-in Atom Python Test. Supporta:

  • eseguire il test sotto il cursore
  • eseguire tutti i test di un modulo
  • test Run doc

supporta anche l'aggiunta di argomenti aggiuntivi per testare l'esecuzione e consente di eseguire unitttest. Anche TestCase.

Problemi correlati