Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to reproduce #1604 #1609

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down