Added code coverage settings and configuration to ignore debug-related lines of code.
- Legacy-Id: 13817
This commit is contained in:
parent
68f68620a7
commit
d26c7085c6
|
@ -471,7 +471,7 @@ TEST_URL_COVERAGE_EXCLUDE = [
|
|||
]
|
||||
|
||||
# These are filename globs. They are fed directly to the coverage code checker.
|
||||
TEST_CODE_COVERAGE_EXCLUDE = [
|
||||
TEST_CODE_COVERAGE_EXCLUDE_FILES = [
|
||||
"*/tests*",
|
||||
"*/admin.py",
|
||||
"*/migrations/*",
|
||||
|
@ -493,6 +493,15 @@ TEST_CODE_COVERAGE_EXCLUDE = [
|
|||
"ietf/stats/backfill_data.py",
|
||||
]
|
||||
|
||||
# These are code line regex patterns
|
||||
TEST_CODE_COVERAGE_EXCLUDE_LINES = [
|
||||
"coverage: *ignore",
|
||||
"debug\.",
|
||||
"unreachable\([^)]*\)",
|
||||
"if settings.DEBUG",
|
||||
"if __name__ == .__main__.:",
|
||||
]
|
||||
|
||||
# These are filename globs. They are used by test_parse_templates() and
|
||||
# get_template_paths()
|
||||
TEST_TEMPLATE_IGNORE = [
|
||||
|
@ -508,7 +517,7 @@ TEST_COVERAGE_LATEST_FILE = os.path.join(BASE_DIR, "../latest-coverage.json")
|
|||
TEST_CODE_COVERAGE_CHECKER = None
|
||||
if SERVER_MODE != 'production':
|
||||
import coverage
|
||||
TEST_CODE_COVERAGE_CHECKER = coverage.Coverage(source=[ BASE_DIR ], cover_pylib=False, omit=TEST_CODE_COVERAGE_EXCLUDE)
|
||||
TEST_CODE_COVERAGE_CHECKER = coverage.Coverage(source=[ BASE_DIR ], cover_pylib=False, omit=TEST_CODE_COVERAGE_EXCLUDE_FILES)
|
||||
|
||||
TEST_CODE_COVERAGE_REPORT_PATH = "coverage/"
|
||||
TEST_CODE_COVERAGE_REPORT_URL = os.path.join(STATIC_URL, TEST_CODE_COVERAGE_REPORT_PATH, "index.html")
|
||||
|
|
|
@ -347,8 +347,10 @@ class CoverageTest(TestCase):
|
|||
# Save to the .coverage file
|
||||
checker.save()
|
||||
# Apply the configured and requested omit and include data
|
||||
checker.config.from_args(ignore_errors=None, omit=settings.TEST_CODE_COVERAGE_EXCLUDE,
|
||||
checker.config.from_args(ignore_errors=None, omit=settings.TEST_CODE_COVERAGE_EXCLUDE_FILES,
|
||||
include=include, file=None)
|
||||
for pattern in settings.TEST_CODE_COVERAGE_EXCLUDE_LINES:
|
||||
checker.exclude(pattern)
|
||||
# Maybe output a html report
|
||||
if self.runner.run_full_test_suite:
|
||||
checker.html_report(directory=settings.TEST_CODE_COVERAGE_REPORT_DIR)
|
||||
|
|
Loading…
Reference in a new issue