diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2023-02-08 21:50:20 -0700 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2023-02-08 22:01:35 -0700 |
commit | 8f3e7b45b3aabf4d7d01dc470010d3d36f30a0ba (patch) | |
tree | 72c9ee920e66586385e4c63c54301a122fe7e0c7 /tests | |
parent | 423fa596325acb8f6bcb37a3502cf7853e5d395a (diff) | |
download | python-coveragepy-git-8f3e7b45b3aabf4d7d01dc470010d3d36f30a0ba.tar.gz |
fix: only write "Wrote report" message if report succeeded.
For example, see [issue
1554](https://github.com/nedbat/coveragepy/issues/1554) for the previous
misleading behavior when the exception being raised wasn't a
CoverageException.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_report.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/tests/test_report.py b/tests/test_report.py index 3d87b514..c85c6b47 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import IO, Iterable, List, Optional +from typing import IO, Iterable, List, Optional, Type import pytest @@ -21,7 +21,7 @@ class FakeReporter: report_type = "fake report file" - def __init__(self, output: str = "", error: bool = False) -> None: + def __init__(self, output: str = "", error: Optional[Type[Exception]] = None) -> None: self.output = output self.error = error self.morfs: Optional[Iterable[TMorf]] = None @@ -31,7 +31,7 @@ class FakeReporter: self.morfs = morfs outfile.write(self.output) if self.error: - raise CoverageException("You asked for it!") + raise self.error("You asked for it!") return 17.25 @@ -57,10 +57,11 @@ class RenderReportTest(CoverageTest): assert f.read().rstrip() == b"Gr\xc3\xa9\xc3\xa8tings!" assert msgs == ["Wrote fake report file to output.txt"] - def test_exception(self) -> None: - fake = FakeReporter(error=True) + @pytest.mark.parametrize("error", [CoverageException, ZeroDivisionError]) + def test_exception(self, error: Type[Exception]) -> None: + fake = FakeReporter(error=error) msgs: List[str] = [] - with pytest.raises(CoverageException, match="You asked for it!"): + with pytest.raises(error, match="You asked for it!"): render_report("output.txt", fake, [], msgs.append) assert self.stdout() == "" self.assert_doesnt_exist("output.txt") |