From 583f0c0deb0c0f232019521ad574ce24a61d66dc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 23 Apr 2024 10:23:38 -0400 Subject: [PATCH] test: add a test for skipping covered functions --- tests/test_html.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_html.py b/tests/test_html.py index e1613daef..bceaf3efe 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -180,6 +180,8 @@ def run_coverage( def assert_htmlcov_files_exist(self) -> None: """Assert that all the expected htmlcov files exist.""" self.assert_exists("htmlcov/index.html") + self.assert_exists("htmlcov/function_index.html") + self.assert_exists("htmlcov/class_index.html") self.assert_exists("htmlcov/main_file_py.html") self.assert_exists("htmlcov/helper1_py.html") self.assert_exists("htmlcov/helper2_py.html") @@ -617,6 +619,26 @@ def normal(): res = self.run_coverage(covargs=dict(source="."), htmlargs=dict(skip_covered=True)) assert res == 100.0 self.assert_doesnt_exist("htmlcov/main_file_py.html") + # Since there are no files to report, we can't collect any region + # information, so there are no region-based index pages. + self.assert_doesnt_exist("htmlcov/function_index.html") + self.assert_doesnt_exist("htmlcov/class_index.html") + + def test_report_skip_covered_100_functions(self) -> None: + self.make_file("main_file.py", """\ + def normal(): + print("z") + def abnormal(): + print("a") + normal() + """) + res = self.run_coverage(covargs=dict(source="."), htmlargs=dict(skip_covered=True)) + assert res == 80.0 + self.assert_exists("htmlcov/main_file_py.html") + # We have a file to report, so we get function and class index pages, + # even though there are no classes. + self.assert_exists("htmlcov/function_index.html") + self.assert_exists("htmlcov/class_index.html") def make_init_and_main(self) -> None: """Helper to create files for skip_empty scenarios."""