test-backend: Display test function in HTML coverage reports.

This commit is contained in:
Adam Sah 2022-05-14 20:52:31 +00:00 committed by Tim Abbott
parent 814841c9ec
commit 492272d597
3 changed files with 12 additions and 1 deletions

View File

@ -481,6 +481,10 @@ Here are some things to consider when writing new tests:
view right from your browser (the tool prints the URL where the report
is exposed in your development environment).
The HTML report also displays which tests executed each line, which
can be handy for finding existing tests for a code path you're
working on.
- **Console output** A properly written test should print nothing to
the console; use `with self.assertLogs` to capture and verify any
logging output. Note that we reconfigure various loggers in

View File

@ -24,6 +24,13 @@ exclude_lines =
[run]
data_file=var/.coverage
# dynamic_context=test_function, combined with using
# html_report(..., show_contexts=True), means the HTML report can detail
# which test(s) executed each line with coverage. This has modest
# overhead but is very useful for finding existing tests for a code path.
dynamic_context=test_function
omit =
*/zulip-venv-cache/*
*/migrations/*

View File

@ -442,7 +442,7 @@ def main() -> None:
print("Printing coverage data")
cov.report(show_missing=False)
cov.xml_report(outfile="var/coverage.xml")
cov.html_report(directory="var/coverage")
cov.html_report(directory="var/coverage", show_contexts=True)
print("HTML report saved; visit at http://127.0.0.1:9991/coverage/index.html")
if full_suite and not failures and options.coverage:
# Assert that various files have full coverage