Skip to content

Commit 8b7bdc1

Browse files
Better error on missing CSS files. (#390)
Co-authored-by: Gleb Nikonorov <[email protected]>
1 parent 817d04d commit 8b7bdc1

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Release Notes
22
-------------
33

4+
**3.1.1 (unreleased)**
5+
6+
* Fix issue with reporting of missing CSS files. (`#388 <https://github.com/pytest-dev/pytest-html/issues/388>`_)
7+
8+
* Thanks to `@prakhargurunani <https://github.com/prakhargurunani>`_ for reporting and fixing!
9+
410
**3.1.0 (2020-12-2)**
511

612
* Stop attaching test reruns to final test report entries (`#374 <https://github.com/pytest-dev/pytest-html/issues/374>`_)

src/pytest_html/plugin.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,18 @@ def pytest_addoption(parser):
8686
def pytest_configure(config):
8787
htmlpath = config.getoption("htmlpath")
8888
if htmlpath:
89+
missing_css_files = []
8990
for csspath in config.getoption("css"):
9091
if not os.path.exists(csspath):
91-
raise OSError(f"No such file or directory: '{csspath}'")
92+
missing_css_files.append(csspath)
93+
94+
if missing_css_files:
95+
oserror = (
96+
f"Missing CSS file{'s' if len(missing_css_files) > 1 else ''}:"
97+
f" {', '.join(missing_css_files)}"
98+
)
99+
raise OSError(oserror)
100+
92101
if not hasattr(config, "workerinput"):
93102
# prevent opening htmlpath on worker nodes (xdist)
94103
config._html = HTMLReport(htmlpath, config)

testing/test_pytest_html.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,12 +1005,31 @@ def test_css(self, testdir, recwarn, colors):
10051005
assert str(v["path"]) in html
10061006
assert v["style"] in html
10071007

1008-
def test_css_invalid(self, testdir, recwarn):
1008+
@pytest.mark.parametrize(
1009+
"files",
1010+
[
1011+
"style.css",
1012+
["abc.css", "xyz.css"],
1013+
"testdir.makefile('.css', * {color: 'white'}",
1014+
],
1015+
)
1016+
def test_css_invalid(self, testdir, recwarn, files):
10091017
testdir.makepyfile("def test_pass(): pass")
1010-
result = testdir.runpytest("--html", "report.html", "--css", "style.css")
1018+
path = files
1019+
if isinstance(files, list):
1020+
file1 = files[0]
1021+
file2 = files[1]
1022+
result = testdir.runpytest(
1023+
"--html", "report.html", "--css", file1, "--css", file2
1024+
)
1025+
else:
1026+
result = testdir.runpytest("--html", "report.html", "--css", path)
10111027
assert result.ret
10121028
assert len(recwarn) == 0
1013-
assert "No such file or directory: 'style.css'" in result.stderr.str()
1029+
if isinstance(files, list):
1030+
assert files[0] in result.stderr.str() and files[1] in result.stderr.str()
1031+
else:
1032+
assert path in result.stderr.str()
10141033

10151034
def test_css_invalid_no_html(self, testdir):
10161035
testdir.makepyfile("def test_pass(): pass")

0 commit comments

Comments
 (0)