Skip to content

Commit fc507ad

Browse files
committed
test: add a case for an extension-less Python file parse error
1 parent 05a6e8d commit fc507ad

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/test_report.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,20 +736,21 @@ def test_accenteddotpy_not_python(self) -> None:
736736
with pytest.raises(NotPython, match=msg):
737737
self.get_report(cov, morfs=["accented\xe2.py"])
738738

739-
def test_dotpy_not_python_ignored(self) -> None:
740-
# We run a .py file, and when reporting, we can't parse it as Python,
739+
@pytest.mark.parametrize("filename", ["mycode.py", "my_script"])
740+
def test_dotpy_not_python_ignored(self, filename: str) -> None:
741+
# We run a Python file, and when reporting, we can't parse it as Python,
741742
# but we've said to ignore errors, so there's no error reported,
742743
# though we still get a warning.
743-
self.make_file("mycode.py", "This isn't python at all!")
744-
self.make_data_file(lines={"mycode.py": [1]})
744+
self.make_file(filename, "This isn't python at all! I can't cope.")
745+
self.make_data_file(lines={filename: [1]})
745746
cov = coverage.Coverage()
746747
cov.load()
747748
with pytest.raises(NoDataError, match="No data to report."):
748749
with pytest.warns(Warning) as warns:
749-
self.get_report(cov, morfs=["mycode.py"], ignore_errors=True)
750+
self.get_report(cov, morfs=[filename], ignore_errors=True)
750751
assert_coverage_warnings(
751752
warns,
752-
re.compile(r"Couldn't parse Python file '.*[/\\]mycode.py' \(couldnt-parse\)"),
753+
re.compile(rf"Couldn't parse Python file '.*[/\\]{filename}' \(couldnt-parse\)"),
753754
)
754755

755756
def test_dothtml_not_python(self) -> None:

0 commit comments

Comments
 (0)