1
0
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:
Ahmad A. Hussein
2020-07-22 17:37:52 +02:00
committed by Carlton Gibson
parent 21768a99f4
commit 61a0ba43cf
9 changed files with 144 additions and 38 deletions

View File

@@ -23,7 +23,7 @@ else:
from django.test import TestCase, TransactionTestCase
from django.test.runner import default_test_processes
from django.test.selenium import SeleniumTestCaseBase
from django.test.utils import get_runner
from django.test.utils import NullTimeKeeper, TimeKeeper, get_runner
from django.utils.deprecation import (
RemovedInDjango40Warning, RemovedInDjango41Warning,
)
@@ -287,7 +287,8 @@ class ActionSelenium(argparse.Action):
def django_tests(verbosity, interactive, failfast, keepdb, reverse,
test_labels, debug_sql, parallel, tags, exclude_tags,
test_name_patterns, start_at, start_after, pdb, buffer):
test_name_patterns, start_at, start_after, pdb, buffer,
timing):
state = setup(verbosity, test_labels, parallel, start_at, start_after)
extra_tests = []
@@ -309,6 +310,7 @@ def django_tests(verbosity, interactive, failfast, keepdb, reverse,
test_name_patterns=test_name_patterns,
pdb=pdb,
buffer=buffer,
timing=timing,
)
failures = test_runner.run_tests(
test_labels or get_installed(),
@@ -508,6 +510,10 @@ if __name__ == "__main__":
'-b', '--buffer', action='store_true',
help='Discard output of passing tests.',
)
parser.add_argument(
'--timing', action='store_true',
help='Output timings, including database set up and total run time.',
)
if PY37:
parser.add_argument(
'-k', dest='test_name_patterns', action='append',
@@ -568,13 +574,17 @@ if __name__ == "__main__":
options.start_at, options.start_after,
)
else:
failures = django_tests(
options.verbosity, options.interactive, options.failfast,
options.keepdb, options.reverse, options.modules,
options.debug_sql, options.parallel, options.tags,
options.exclude_tags,
getattr(options, 'test_name_patterns', None),
options.start_at, options.start_after, options.pdb, options.buffer,
)
time_keeper = TimeKeeper() if options.timing else NullTimeKeeper()
with time_keeper.timed('Total run'):
failures = django_tests(
options.verbosity, options.interactive, options.failfast,
options.keepdb, options.reverse, options.modules,
options.debug_sql, options.parallel, options.tags,
options.exclude_tags,
getattr(options, 'test_name_patterns', None),
options.start_at, options.start_after, options.pdb, options.buffer,
options.timing,
)
time_keeper.print_results()
if failures:
sys.exit(1)