mirror of
https://github.com/django/django.git
synced 2025-08-31 07:47:37 +00:00
Fixed #32552 -- Added logger argument to DiscoverRunner.
This commit is contained in:
parent
022d29c934
commit
b263f4b69d
4 changed files with 61 additions and 22 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue