From 5a669ae2f4e1665f475d384ab762bcf4ddc5660b Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Fri, 9 Feb 2018 18:39:52 +0530 Subject: [PATCH] Fixed #29106 -- Made DiscoverRunner display selected test tags. --- django/test/runner.py | 5 +++++ tests/test_runner/test_discover_runner.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/django/test/runner.py b/django/test/runner.py index d89d734c70..9ed78a6be8 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -522,6 +522,11 @@ class DiscoverRunner: suite.addTest(test) 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 = reorder_suite(suite, self.reorder_by, self.reverse) diff --git a/tests/test_runner/test_discover_runner.py b/tests/test_runner/test_discover_runner.py index 5efcbe4f5d..e7c7e4dad1 100644 --- a/tests/test_runner/test_discover_runner.py +++ b/tests/test_runner/test_discover_runner.py @@ -5,6 +5,7 @@ from unittest import TestSuite, TextTestRunner, defaultTestLoader from django.test import TestCase from django.test.runner import DiscoverRunner +from django.test.utils import captured_stdout @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', 'baz']), 1) 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())