Fixed #32552 -- Added logger argument to DiscoverRunner.

This commit is contained in:
Chris Jerdonek 2021-08-09 13:18:51 -04:00 committed by Mariusz Felisiak
parent 022d29c934
commit b263f4b69d
4 changed files with 61 additions and 22 deletions

View file

@ -623,6 +623,27 @@ class DiscoverRunnerTests(SimpleTestCase):
runner.log(msg, level)
self.assertEqual(stdout.getvalue(), f'{msg}\n' if output else '')
def test_log_logger(self):
logger = logging.getLogger('test.logging')
cases = [
(None, 'INFO:test.logging:log message'),
# Test a low custom logging level.
(5, 'Level 5:test.logging:log message'),
(logging.DEBUG, 'DEBUG:test.logging:log message'),
(logging.INFO, 'INFO:test.logging:log message'),
(logging.WARNING, 'WARNING:test.logging:log message'),
# Test a high custom logging level.
(45, 'Level 45:test.logging:log message'),
]
for level, expected in cases:
with self.subTest(level=level):
runner = DiscoverRunner(logger=logger)
# Pass a logging level smaller than the smallest level in cases
# in order to capture all messages.
with self.assertLogs('test.logging', level=1) as cm:
runner.log('log message', level)
self.assertEqual(cm.output, [expected])
class DiscoverRunnerGetDatabasesTests(SimpleTestCase):
runner = DiscoverRunner(verbosity=2)