Utilizzo la struttura python
unittest
. È possibile specificare per le abilità del framework un timeout per il test? Se no, è possibile specificare con garbo un timeout
per tutti i test e per alcuni test separati un valore privato per ognuno?
Voglio definire un global timeout
per tutti i test (lo useranno per impostazione predefinita) e un timeout per alcuni test che possono richiedere molto tempo.Come specificare il timeout del test per Python Unittest?
13
A
risposta
13
Per quanto ne so, lo unittest
non contiene alcun supporto per il timeout dei test.
Puoi provare la libreria timeout-decorator
da PyPI. Applicare il decoratore sui singoli test per farli terminare se prendono troppo tempo:
import timeout_decorator
class TestCaseWithTimeouts(unittest.TestCase):
# ... whatever ...
@timeout_decorator.timeout(LOCAL_TIMEOUT)
def test_that_can_take_too_long(self):
sleep(float('inf'))
# ... whatever else ...
Per creare un timeout globale, è possibile sostituire chiamare
unittest.main()
con
timeout_decorator.timeout(GLOBAL_TIMEOUT)(unittest.main)()
Problemi correlati
- 1. Come specificare il timeout per XmlReader?
- 2. Ordine dei test in python unittest
- 3. Test in Python - come usare assertRaises in testing usando unittest?
- 4. Test reindirizzamento nel pallone con Python Unittest
- 5. Python unittest, fai qualcosa solo se il test fallisce
- 6. Come eseguire la ricerca di unittest da "python setup.py test"?
- 7. metodi unittest python
- 8. Come genero un test suite in python unittest
- 9. override funzione python locale-variabile in unittest
- 10. Timeout del sottoprocesso Python?
- 11. unittest per nessun tipo in python?
- 12. ipdb con modulo unittest python
- 13. Python unittest: eseguire test in un altro modulo
- 14. di Python unittest e dinamica creazione di casi di test
- 15. Per loop in unittest
- 16. Come prolungare il timeout per i test in circleci?
- 17. Python Unittest discovery con sottocartelle
- 18. Come specificare un timeout HttpWebRequest globale?
- 19. Django unittest test database di sola lettura
- 20. Sovrascrivi auto_now per unittest
- 21. test di riutilizzo unittest per famiglie di classi
- 22. Python unittest - Asserting dictionary with lists
- 23. Come specificare i test da eseguire con "nosetests python setup.py"
- 24. Simulazione del passare del tempo in unittest
- 25. Passando argomenti (per argparse) con scoprimento unittest
- 26. Python unittest problemi di importazione
- 27. Python unittest: come soddisfare la copertura del naso per l'importazione di pacchetti
- 28. Come eseguire il test dell'unità di scrittura di file usando pyton unittest
- 29. Test unitario con timeout
- 30. Python unittest, salta i test quando si utilizza una classe di test di base
Interessante. Non sto usando 'unittest.main()', ma spero di poter adottare 'decorator' per il mio caso. Ma i miei test non stanno andando in single thread ... – Jury
@Jury Controlla la sezione "Multithreading" in ['timeout-decorator' reference] (https://pypi.python.org/pypi/timeout-decorator) - hai solo è necessario utilizzare 'timeout_decorator.timeout (TIMEOUT, use_signals = False)' in ambiente multi-thread. – Lav
Sì, l'ho visto. Ci proverò. – Jury