summaryrefslogtreecommitdiff
path: root/tests/test_html.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-05-30 17:39:20 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-05-30 18:03:05 -0400
commit30c023b5b74f9c798645cbb3f35362ae046a4c25 (patch)
treee86df1a4c044ec9b2919068297dfd91a382eeb84 /tests/test_html.py
parent22fe2eb167a18dda8fd3e14cbf9166a1c7331fb9 (diff)
downloadpython-coveragepy-git-30c023b5b74f9c798645cbb3f35362ae046a4c25.tar.gz
feat: warnings are now real warnings
This makes coverage warnings visible when running test suites under pytest. But it also means some uninteresting warnings would show up in our own test suite, so we had to catch or suppress those.
Diffstat (limited to 'tests/test_html.py')
-rw-r--r--tests/test_html.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/test_html.py b/tests/test_html.py
index c9dbacc8..56519a64 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -24,7 +24,7 @@ from coverage.report import get_analysis_to_report
from tests.coveragetest import CoverageTest, TESTS_DIR
from tests.goldtest import gold_path
from tests.goldtest import compare, contains, doesnt_contain, contains_any
-from tests.helpers import change_dir
+from tests.helpers import assert_coverage_warnings, change_dir
class HtmlTestHelpers(CoverageTest):
@@ -341,13 +341,14 @@ class HtmlWithUnparsableFilesTest(HtmlTestHelpers, CoverageTest):
self.make_file("innocuous.py", "a = 2")
cov = coverage.Coverage()
self.start_import_stop(cov, "main")
+
self.make_file("innocuous.py", "<h1>This isn't python!</h1>")
- cov.html_report(ignore_errors=True)
- msg = "Expected a warning to be thrown when an invalid python file is parsed"
- assert 1 == len(cov._warnings), msg
- msg = "Warning message should be in 'invalid file' warning"
- assert "Couldn't parse Python file" in cov._warnings[0], msg
- assert "innocuous.py" in cov._warnings[0], "Filename should be in 'invalid file' warning"
+ with pytest.warns(Warning) as warns:
+ cov.html_report(ignore_errors=True)
+ assert_coverage_warnings(
+ warns,
+ re.compile(r"Couldn't parse Python file '.*innocuous.py' \(couldnt-parse\)"),
+ )
self.assert_exists("htmlcov/index.html")
# This would be better as a glob, if the HTML layout changes:
self.assert_doesnt_exist("htmlcov/innocuous.html")