mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Refs #31811 -- Added optional timing outputs to the test runner.
This commit is contained in:
committed by
Carlton Gibson
parent
21768a99f4
commit
61a0ba43cf
@@ -8,7 +8,9 @@ from unittest import (
|
||||
from django.db import connections
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.runner import DiscoverRunner
|
||||
from django.test.utils import captured_stderr, captured_stdout
|
||||
from django.test.utils import (
|
||||
NullTimeKeeper, TimeKeeper, captured_stderr, captured_stdout,
|
||||
)
|
||||
from django.utils.version import PY37
|
||||
|
||||
|
||||
@@ -324,6 +326,24 @@ class DiscoverRunnerTests(SimpleTestCase):
|
||||
DiscoverRunner(enable_faulthandler=False)
|
||||
mocked_enable.assert_not_called()
|
||||
|
||||
def test_timings_not_captured(self):
|
||||
runner = DiscoverRunner(timing=False)
|
||||
with captured_stderr() as stderr:
|
||||
with runner.time_keeper.timed('test'):
|
||||
pass
|
||||
runner.time_keeper.print_results()
|
||||
self.assertTrue(isinstance(runner.time_keeper, NullTimeKeeper))
|
||||
self.assertNotIn('test', stderr.getvalue())
|
||||
|
||||
def test_timings_captured(self):
|
||||
runner = DiscoverRunner(timing=True)
|
||||
with captured_stderr() as stderr:
|
||||
with runner.time_keeper.timed('test'):
|
||||
pass
|
||||
runner.time_keeper.print_results()
|
||||
self.assertTrue(isinstance(runner.time_keeper, TimeKeeper))
|
||||
self.assertIn('test', stderr.getvalue())
|
||||
|
||||
|
||||
class DiscoverRunnerGetDatabasesTests(SimpleTestCase):
|
||||
runner = DiscoverRunner(verbosity=2)
|
||||
|
||||
Reference in New Issue
Block a user