mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #34210 -- Added unittest's durations option to the test runner.
This commit is contained in:
committed by
Mariusz Felisiak
parent
27b399d235
commit
74b5074174
@@ -16,6 +16,7 @@ from django.test.utils import (
|
||||
captured_stderr,
|
||||
captured_stdout,
|
||||
)
|
||||
from django.utils.version import PY312
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -765,6 +766,22 @@ class DiscoverRunnerTests(SimpleTestCase):
|
||||
failures = runner.suite_result(suite, result)
|
||||
self.assertEqual(failures, expected_failures)
|
||||
|
||||
@unittest.skipUnless(PY312, "unittest --durations option requires Python 3.12")
|
||||
def test_durations(self):
|
||||
with captured_stderr() as stderr, captured_stdout():
|
||||
runner = DiscoverRunner(durations=10)
|
||||
suite = runner.build_suite(["test_runner_apps.simple.tests.SimpleCase1"])
|
||||
runner.run_suite(suite)
|
||||
self.assertIn("Slowest test durations", stderr.getvalue())
|
||||
|
||||
@unittest.skipUnless(PY312, "unittest --durations option requires Python 3.12")
|
||||
def test_durations_debug_sql(self):
|
||||
with captured_stderr() as stderr, captured_stdout():
|
||||
runner = DiscoverRunner(durations=10, debug_sql=True)
|
||||
suite = runner.build_suite(["test_runner_apps.simple.SimpleCase1"])
|
||||
runner.run_suite(suite)
|
||||
self.assertIn("Slowest test durations", stderr.getvalue())
|
||||
|
||||
|
||||
class DiscoverRunnerGetDatabasesTests(SimpleTestCase):
|
||||
runner = DiscoverRunner(verbosity=2)
|
||||
|
||||
Reference in New Issue
Block a user