Fixed #29106 -- Made DiscoverRunner display selected test tags.

This commit is contained in:
Sanyam Khurana 2018-02-09 18:39:52 +05:30 committed by Tim Graham
parent cb7860cced
commit 5a669ae2f4
2 changed files with 18 additions and 0 deletions

View File

@ -522,6 +522,11 @@ class DiscoverRunner:
suite.addTest(test) suite.addTest(test)
if self.tags or self.exclude_tags: if self.tags or self.exclude_tags:
if self.verbosity >= 2:
if self.tags:
print('Including test tag(s): %s.' % ', '.join(sorted(self.tags)))
if self.exclude_tags:
print('Excluding test tag(s): %s.' % ', '.join(sorted(self.exclude_tags)))
suite = filter_tests_by_tags(suite, self.tags, self.exclude_tags) suite = filter_tests_by_tags(suite, self.tags, self.exclude_tags)
suite = reorder_suite(suite, self.reorder_by, self.reverse) suite = reorder_suite(suite, self.reorder_by, self.reverse)

View File

@ -5,6 +5,7 @@ from unittest import TestSuite, TextTestRunner, defaultTestLoader
from django.test import TestCase from django.test import TestCase
from django.test.runner import DiscoverRunner from django.test.runner import DiscoverRunner
from django.test.utils import captured_stdout
@contextmanager @contextmanager
@ -210,3 +211,15 @@ class DiscoverRunnerTest(TestCase):
self.assertEqual(count_tests(tags=['foo'], exclude_tags=['bar']), 2) self.assertEqual(count_tests(tags=['foo'], exclude_tags=['bar']), 2)
self.assertEqual(count_tests(tags=['foo'], exclude_tags=['bar', 'baz']), 1) self.assertEqual(count_tests(tags=['foo'], exclude_tags=['bar', 'baz']), 1)
self.assertEqual(count_tests(exclude_tags=['foo']), 0) self.assertEqual(count_tests(exclude_tags=['foo']), 0)
def test_included_tags_displayed(self):
runner = DiscoverRunner(tags=['foo', 'bar'], verbosity=2)
with captured_stdout() as stdout:
runner.build_suite(['test_runner_apps.tagged.tests'])
self.assertIn('Including test tag(s): bar, foo.\n', stdout.getvalue())
def test_excluded_tags_displayed(self):
runner = DiscoverRunner(exclude_tags=['foo', 'bar'], verbosity=3)
with captured_stdout() as stdout:
runner.build_suite(['test_runner_apps.tagged.tests'])
self.assertIn('Excluding test tag(s): bar, foo.\n', stdout.getvalue())