Skip to content

Commit 583f0c0

Browse files
committed
test: add a test for skipping covered functions
1 parent b115ed3 commit 583f0c0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_html.py

+22
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ def run_coverage(
180180
def assert_htmlcov_files_exist(self) -> None:
181181
"""Assert that all the expected htmlcov files exist."""
182182
self.assert_exists("htmlcov/index.html")
183+
self.assert_exists("htmlcov/function_index.html")
184+
self.assert_exists("htmlcov/class_index.html")
183185
self.assert_exists("htmlcov/main_file_py.html")
184186
self.assert_exists("htmlcov/helper1_py.html")
185187
self.assert_exists("htmlcov/helper2_py.html")
@@ -617,6 +619,26 @@ def normal():
617619
res = self.run_coverage(covargs=dict(source="."), htmlargs=dict(skip_covered=True))
618620
assert res == 100.0
619621
self.assert_doesnt_exist("htmlcov/main_file_py.html")
622+
# Since there are no files to report, we can't collect any region
623+
# information, so there are no region-based index pages.
624+
self.assert_doesnt_exist("htmlcov/function_index.html")
625+
self.assert_doesnt_exist("htmlcov/class_index.html")
626+
627+
def test_report_skip_covered_100_functions(self) -> None:
628+
self.make_file("main_file.py", """\
629+
def normal():
630+
print("z")
631+
def abnormal():
632+
print("a")
633+
normal()
634+
""")
635+
res = self.run_coverage(covargs=dict(source="."), htmlargs=dict(skip_covered=True))
636+
assert res == 80.0
637+
self.assert_exists("htmlcov/main_file_py.html")
638+
# We have a file to report, so we get function and class index pages,
639+
# even though there are no classes.
640+
self.assert_exists("htmlcov/function_index.html")
641+
self.assert_exists("htmlcov/class_index.html")
620642

621643
def make_init_and_main(self) -> None:
622644
"""Helper to create files for skip_empty scenarios."""

0 commit comments

Comments
 (0)