1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #29127 -- Prevented DiscoverRunner from hiding tagged test with syntax errors.

This mades _FailedTest objects always match tags in DiscoverRunner.
This commit is contained in:
Chris Jerdonek
2021-03-26 05:14:43 -07:00
committed by Mariusz Felisiak
parent 7c08f26bf0
commit 038940cf55
5 changed files with 37 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ import os
import unittest.loader
from argparse import ArgumentParser
from contextlib import contextmanager
from importlib import import_module
from unittest import TestSuite, TextTestRunner, defaultTestLoader, mock
from django.db import connections
@@ -259,6 +260,18 @@ class DiscoverRunnerTests(SimpleTestCase):
self.assertEqual(count_tests(tags=['foo'], exclude_tags=['bar', 'baz']), 1)
self.assertEqual(count_tests(exclude_tags=['foo']), 0)
def test_tag_fail_to_load(self):
with self.assertRaises(SyntaxError):
import_module('test_runner_apps.tagged.tests_syntax_error')
runner = DiscoverRunner(tags=['syntax_error'])
# A label that doesn't exist or cannot be loaded due to syntax errors
# is always considered matching.
suite = runner.build_suite(['doesnotexist', 'test_runner_apps.tagged'])
self.assertEqual([test.id() for test in suite], [
'unittest.loader._FailedTest.doesnotexist',
'unittest.loader._FailedTest.test_runner_apps.tagged.tests_syntax_error',
])
def test_included_tags_displayed(self):
runner = DiscoverRunner(tags=['foo', 'bar'], verbosity=2)
with captured_stdout() as stdout: