Skip to content

Commit

Permalink
Add tests to reproduce #1604
Browse files Browse the repository at this point in the history
  • Loading branch information
marcgibbons committed Apr 24, 2023
1 parent 5b87af0 commit 714756a
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,61 @@ 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()
config = """
[run]
relative_files = true
"""
self.make_file(".coveragerc", config)
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()
config = """
[run]
relative_files = true
"""
self.make_file(".coveragerc", config)
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", "")
Expand Down

0 comments on commit 714756a

Please sign in to comment.