summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakub Paczkowski <jakub@paczkowski.eu>2015-11-07 14:57:56 +0100
committerTim Graham <timograham@gmail.com>2016-02-17 09:44:18 -0500
commitd4dc775620fc57e962165eab98a77264e3dd16b2 (patch)
treeef18bd2705ca738d087c4e725c489cffada1945d /tests
parent0db7e61076116c2d93d61f98ef31690542359e48 (diff)
Fixed #25735 -- Added support for test tags to DiscoverRunner.
Thanks Carl Meyer, Claude Paroz, and Simon Charette for review.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runtests.py24
-rw-r--r--tests/test_discovery_sample/tests_sample.py13
-rw-r--r--tests/test_runner/test_discover_runner.py20
3 files changed, 50 insertions, 7 deletions
diff --git a/tests/runtests.py b/tests/runtests.py
index 4be186c123..6fca3dc6a6 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -234,7 +234,7 @@ def actual_test_processes(parallel):
def django_tests(verbosity, interactive, failfast, keepdb, reverse,
- test_labels, debug_sql, parallel):
+ test_labels, debug_sql, parallel, tags, exclude_tags):
state = setup(verbosity, test_labels, parallel)
extra_tests = []
@@ -251,6 +251,8 @@ def django_tests(verbosity, interactive, failfast, keepdb, reverse,
reverse=reverse,
debug_sql=debug_sql,
parallel=actual_test_processes(parallel),
+ tags=tags,
+ exclude_tags=exclude_tags,
)
failures = test_runner.run_tests(
test_labels or get_installed(),
@@ -270,6 +272,10 @@ def get_subprocess_args(options):
subprocess_args.append('--verbosity=%s' % options.verbosity)
if not options.interactive:
subprocess_args.append('--noinput')
+ if options.tags:
+ subprocess_args.append('--tag=%s' % options.tags)
+ if options.exclude_tags:
+ subprocess_args.append('--exclude_tag=%s' % options.exclude_tags)
return subprocess_args
@@ -399,6 +405,12 @@ if __name__ == "__main__":
'--parallel', dest='parallel', nargs='?', default=0, type=int,
const=default_test_processes(), metavar='N',
help='Run tests using up to N parallel processes.')
+ parser.add_argument(
+ '--tag', dest='tags', action='append',
+ help='Run only tests with the specified tags. Can be used multiple times.')
+ parser.add_argument(
+ '--exclude-tag', dest='exclude_tags', action='append',
+ help='Do not run tests with the specified tag. Can be used multiple times.')
options = parser.parse_args()
@@ -433,9 +445,11 @@ if __name__ == "__main__":
elif options.pair:
paired_tests(options.pair, options, options.modules, options.parallel)
else:
- failures = django_tests(options.verbosity, options.interactive,
- options.failfast, options.keepdb,
- options.reverse, options.modules,
- options.debug_sql, options.parallel)
+ failures = django_tests(
+ options.verbosity, options.interactive, options.failfast,
+ options.keepdb, options.reverse, options.modules,
+ options.debug_sql, options.parallel, options.tags,
+ options.exclude_tags,
+ )
if failures:
sys.exit(bool(failures))
diff --git a/tests/test_discovery_sample/tests_sample.py b/tests/test_discovery_sample/tests_sample.py
index eb977e44fb..53588709ea 100644
--- a/tests/test_discovery_sample/tests_sample.py
+++ b/tests/test_discovery_sample/tests_sample.py
@@ -2,6 +2,7 @@ import doctest
from unittest import TestCase
from django.test import SimpleTestCase, TestCase as DjangoTestCase
+from django.test.utils import tag
from . import doctests
@@ -29,6 +30,18 @@ class EmptyTestCase(TestCase):
pass
+@tag('slow')
+class TaggedTestCase(TestCase):
+
+ @tag('fast')
+ def test_single_tag(self):
+ self.assertEqual(1, 1)
+
+ @tag('fast', 'core')
+ def test_multiple_tags(self):
+ self.assertEqual(1, 1)
+
+
def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(doctests))
return tests
diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py
index 833cca96ea..37c18b2f8f 100644
--- a/tests/test_runner/test_discover_runner.py
+++ b/tests/test_runner/test_discover_runner.py
@@ -25,7 +25,7 @@ class DiscoverRunnerTest(TestCase):
["test_discovery_sample.tests_sample"],
).countTestCases()
- self.assertEqual(count, 4)
+ self.assertEqual(count, 6)
def test_dotted_test_class_vanilla_unittest(self):
count = DiscoverRunner().build_suite(
@@ -61,7 +61,7 @@ class DiscoverRunnerTest(TestCase):
["test_discovery_sample/"],
).countTestCases()
- self.assertEqual(count, 5)
+ self.assertEqual(count, 7)
def test_empty_label(self):
"""
@@ -165,3 +165,19 @@ class DiscoverRunnerTest(TestCase):
def test_overridable_test_loader(self):
self.assertEqual(DiscoverRunner().test_loader, defaultTestLoader)
+
+ def test_tags(self):
+ runner = DiscoverRunner(tags=['core'])
+ self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 1)
+ runner = DiscoverRunner(tags=['fast'])
+ self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 2)
+ runner = DiscoverRunner(tags=['slow'])
+ self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 2)
+
+ def test_exclude_tags(self):
+ runner = DiscoverRunner(tags=['fast'], exclude_tags=['core'])
+ self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 1)
+ runner = DiscoverRunner(tags=['fast'], exclude_tags=['slow'])
+ self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 0)
+ runner = DiscoverRunner(exclude_tags=['slow'])
+ self.assertEqual(runner.build_suite(['test_discovery_sample.tests_sample']).countTestCases(), 4)