How do you skip unit test in Django?

How to force skip unit test in Django?

@skipif and @skipunless are all I found, but I just want to skip the test right now for debugging purposes, while I get a few corrections.

+44
django unit-testing skip django-unittest
Jul 08 '13 at 5:08 on
source share
2 answers

There are several decorators in the python unittest module:

There is a simple old @skip :

 from unittest import skip @skip("Don't want to test") def test_something(): ... 

If you cannot use @skip for some reason, @skipIf should work. Just fool it to always skip with the True argument:

 @skipIf(True, "I don't want to run this test yet") def test_something(): ... 

unittest docs

Missed Test Documents

If you just want to not run certain test files, the best way is probably to use fab or another tool and run certain tests.

+69
Jul 08 '13 at 5:25
source share

Django 1.10 allows you to use tags for unit tests. Then you can use the --exclude-tag=tag_name to exclude specific tags:

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

In the above example, to exclude tests with the < slow "tag that you run:

 $ ./manage.py test --exclude-tag=slow 
+19
Sep 21 '16 at 16:27
source share



All Articles