Come saltare forzatamente un test unitario in Django?Come si salta un test unitario in Django?
@skipif e @skipunless è tutto quello che ho trovato, ma voglio saltare un test proprio ora per scopi di debug mentre ottengo alcune cose raddrizzate.
Come saltare forzatamente un test unitario in Django?Come si salta un test unitario in Django?
@skipif e @skipunless è tutto quello che ho trovato, ma voglio saltare un test proprio ora per scopi di debug mentre ottengo alcune cose raddrizzate.
modulo unittest del Python ha un paio di decoratori:
C'è pianura vecchio @skip
:
from unittest import skip
@skip("Don't want to test")
def test_something():
...
Se non è possibile utilizzare @skip
per qualche motivo, @skipIf
dovrebbe funzionare. Basta trucco per saltare sempre con l'argomento True
:
@skipIf(True, "I don't want to run this test yet")
def test_something():
...
Se stai cercando di semplicemente non eseguire alcuni file di test, il modo migliore è probabilmente quello di usare fab
o altro strumento ed eseguire test particolari.
Django 1.10 allows use of tags per test di unità. È quindi possibile utilizzare il flag --exclude-tag=tag_name
di escludere determinati tag:
from django.test import tag
class SampleTestCase(TestCase):
@tag('fast')
def test_fast(self):
...
@tag('slow')
def test_slow(self):
...
@tag('slow', 'core')
def test_slow_but_core(self):
...
Nell'esempio di cui sopra, per escludere i test con il tag "slow
" si eseguire:
$ ./manage.py test --exclude-tag=slow
Ahh, non l'ho fatto sappi che potresti ingannare l'interprete con quella vera argomentazione. Grazie! – user798719