From b321a62d90b1ca02026ac3c3d6f24808ec823102 Mon Sep 17 00:00:00 2001 From: Marc Gibbons <1726961+marcgibbons@users.noreply.github.com> Date: Mon, 24 Apr 2023 12:35:12 -0600 Subject: [PATCH] Add tests to reproduce #1604 (#1609) --- tests/test_summary.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/test_summary.py b/tests/test_summary.py index f532a7b1f..f2158c93f 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -142,6 +142,59 @@ def test_report_including(self) -> None: assert "mycode.py " in report assert self.last_line_squeezed(report) == "TOTAL 4 0 100%" + def test_report_include_relative_files_and_path(self) -> None: + """ + Test that when relative_files is True and a relative path to a module + is included, coverage is reported for the module. + + Ref: https://github.com/nedbat/coveragepy/issues/1604 + """ + self.make_mycode() + self.make_file(".coveragerc", """\ + [run] + relative_files = true + """) + self.make_file("submodule/mycode.py", "import mycode") + + cov = coverage.Coverage() + self.start_import_stop(cov, "submodule/mycode") + report = self.get_report(cov, include="submodule/mycode.py") + + # Name Stmts Miss Cover + # --------------------------------------- + # submodule/mycode.py 1 0 100% + # --------------------------------------- + # TOTAL 1 0 100% + + assert "submodule/mycode.py " in report + assert self.last_line_squeezed(report) == "TOTAL 1 0 100%" + + def test_report_include_relative_files_and_wildcard_path(self) -> None: + self.make_mycode() + self.make_file(".coveragerc", """\ + [run] + relative_files = true + """) + self.make_file("submodule/mycode.py", "import nested.submodule.mycode") + self.make_file("nested/submodule/mycode.py", "import mycode") + + cov = coverage.Coverage() + self.start_import_stop(cov, "submodule/mycode") + report = self.get_report(cov, include="*/submodule/mycode.py") + + # Name Stmts Miss Cover + # ------------------------------------------------- + # nested/submodule/mycode.py 1 0 100% + # submodule/mycode.py 1 0 100% + # ------------------------------------------------- + # TOTAL 2 0 100% + + reported_files = [line.split()[0] for line in report.splitlines()[2:4]] + assert reported_files == [ + "nested/submodule/mycode.py", + "submodule/mycode.py", + ] + def test_omit_files_here(self) -> None: # https://github.com/nedbat/coveragepy/issues/1407 self.make_file("foo.py", "")