Skip to content

Commit d26c708

Browse files
committed
Added code coverage settings and configuration to ignore debug-related lines of code.
- Legacy-Id: 13817
1 parent 68f6862 commit d26c708

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

ietf/settings.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def skip_unreadable_post(record):
471471
]
472472

473473
# These are filename globs. They are fed directly to the coverage code checker.
474-
TEST_CODE_COVERAGE_EXCLUDE = [
474+
TEST_CODE_COVERAGE_EXCLUDE_FILES = [
475475
"*/tests*",
476476
"*/admin.py",
477477
"*/migrations/*",
@@ -493,6 +493,15 @@ def skip_unreadable_post(record):
493493
"ietf/stats/backfill_data.py",
494494
]
495495

496+
# These are code line regex patterns
497+
TEST_CODE_COVERAGE_EXCLUDE_LINES = [
498+
"coverage: *ignore",
499+
"debug\.",
500+
"unreachable\([^)]*\)",
501+
"if settings.DEBUG",
502+
"if __name__ == .__main__.:",
503+
]
504+
496505
# These are filename globs. They are used by test_parse_templates() and
497506
# get_template_paths()
498507
TEST_TEMPLATE_IGNORE = [
@@ -508,7 +517,7 @@ def skip_unreadable_post(record):
508517
TEST_CODE_COVERAGE_CHECKER = None
509518
if SERVER_MODE != 'production':
510519
import coverage
511-
TEST_CODE_COVERAGE_CHECKER = coverage.Coverage(source=[ BASE_DIR ], cover_pylib=False, omit=TEST_CODE_COVERAGE_EXCLUDE)
520+
TEST_CODE_COVERAGE_CHECKER = coverage.Coverage(source=[ BASE_DIR ], cover_pylib=False, omit=TEST_CODE_COVERAGE_EXCLUDE_FILES)
512521

513522
TEST_CODE_COVERAGE_REPORT_PATH = "coverage/"
514523
TEST_CODE_COVERAGE_REPORT_URL = os.path.join(STATIC_URL, TEST_CODE_COVERAGE_REPORT_PATH, "index.html")

ietf/utils/test_runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,10 @@ def code_coverage_test(self):
347347
# Save to the .coverage file
348348
checker.save()
349349
# Apply the configured and requested omit and include data
350-
checker.config.from_args(ignore_errors=None, omit=settings.TEST_CODE_COVERAGE_EXCLUDE,
350+
checker.config.from_args(ignore_errors=None, omit=settings.TEST_CODE_COVERAGE_EXCLUDE_FILES,
351351
include=include, file=None)
352+
for pattern in settings.TEST_CODE_COVERAGE_EXCLUDE_LINES:
353+
checker.exclude(pattern)
352354
# Maybe output a html report
353355
if self.runner.run_full_test_suite:
354356
checker.html_report(directory=settings.TEST_CODE_COVERAGE_REPORT_DIR)

0 commit comments

Comments
 (0)