Skip to content

Commit 3344a78

Browse files
marcgibbonsnedbat
authored andcommitted
tet: add tests to reproduce #1604 (#1609)
1 parent 23717ce commit 3344a78

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/test_summary.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,59 @@ def test_report_including(self) -> None:
142142
assert "mycode.py " in report
143143
assert self.last_line_squeezed(report) == "TOTAL 4 0 100%"
144144

145+
def test_report_include_relative_files_and_path(self) -> None:
146+
"""
147+
Test that when relative_files is True and a relative path to a module
148+
is included, coverage is reported for the module.
149+
150+
Ref: https://github.com/nedbat/coveragepy/issues/1604
151+
"""
152+
self.make_mycode()
153+
self.make_file(".coveragerc", """\
154+
[run]
155+
relative_files = true
156+
""")
157+
self.make_file("submodule/mycode.py", "import mycode")
158+
159+
cov = coverage.Coverage()
160+
self.start_import_stop(cov, "submodule/mycode")
161+
report = self.get_report(cov, include="submodule/mycode.py")
162+
163+
# Name Stmts Miss Cover
164+
# ---------------------------------------
165+
# submodule/mycode.py 1 0 100%
166+
# ---------------------------------------
167+
# TOTAL 1 0 100%
168+
169+
assert "submodule/mycode.py " in report
170+
assert self.last_line_squeezed(report) == "TOTAL 1 0 100%"
171+
172+
def test_report_include_relative_files_and_wildcard_path(self) -> None:
173+
self.make_mycode()
174+
self.make_file(".coveragerc", """\
175+
[run]
176+
relative_files = true
177+
""")
178+
self.make_file("submodule/mycode.py", "import nested.submodule.mycode")
179+
self.make_file("nested/submodule/mycode.py", "import mycode")
180+
181+
cov = coverage.Coverage()
182+
self.start_import_stop(cov, "submodule/mycode")
183+
report = self.get_report(cov, include="*/submodule/mycode.py")
184+
185+
# Name Stmts Miss Cover
186+
# -------------------------------------------------
187+
# nested/submodule/mycode.py 1 0 100%
188+
# submodule/mycode.py 1 0 100%
189+
# -------------------------------------------------
190+
# TOTAL 2 0 100%
191+
192+
reported_files = [line.split()[0] for line in report.splitlines()[2:4]]
193+
assert reported_files == [
194+
"nested/submodule/mycode.py",
195+
"submodule/mycode.py",
196+
]
197+
145198
def test_omit_files_here(self) -> None:
146199
# https://github.com/nedbat/coveragepy/issues/1407
147200
self.make_file("foo.py", "")

0 commit comments

Comments
 (0)