2013-07-08 7 views

risposta

74

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(): 
    ... 

unittest docs

Docs on skipping tests

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.

+0

Ahh, non l'ho fatto sappi che potresti ingannare l'interprete con quella vera argomentazione. Grazie! – user798719

22

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