Skip to content

Commit

Permalink
Better error on missing CSS files. (pytest-dev#390)
Browse files Browse the repository at this point in the history
Co-authored-by: Gleb Nikonorov <[email protected]>
  • Loading branch information
FirePing32 and gnikonorov authored Dec 9, 2020
1 parent 817d04d commit 8b7bdc1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release Notes
-------------

**3.1.1 (unreleased)**

* Fix issue with reporting of missing CSS files. (`#388 <https://github.com/pytest-dev/pytest-html/issues/388>`_)

* Thanks to `@prakhargurunani <https://github.com/prakhargurunani>`_ for reporting and fixing!

**3.1.0 (2020-12-2)**

* Stop attaching test reruns to final test report entries (`#374 <https://github.com/pytest-dev/pytest-html/issues/374>`_)
Expand Down
11 changes: 10 additions & 1 deletion src/pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,18 @@ def pytest_addoption(parser):
def pytest_configure(config):
htmlpath = config.getoption("htmlpath")
if htmlpath:
missing_css_files = []
for csspath in config.getoption("css"):
if not os.path.exists(csspath):
raise OSError(f"No such file or directory: '{csspath}'")
missing_css_files.append(csspath)

if missing_css_files:
oserror = (
f"Missing CSS file{'s' if len(missing_css_files) > 1 else ''}:"
f" {', '.join(missing_css_files)}"
)
raise OSError(oserror)

if not hasattr(config, "workerinput"):
# prevent opening htmlpath on worker nodes (xdist)
config._html = HTMLReport(htmlpath, config)
Expand Down
25 changes: 22 additions & 3 deletions testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,12 +1005,31 @@ def test_css(self, testdir, recwarn, colors):
assert str(v["path"]) in html
assert v["style"] in html

def test_css_invalid(self, testdir, recwarn):
@pytest.mark.parametrize(
"files",
[
"style.css",
["abc.css", "xyz.css"],
"testdir.makefile('.css', * {color: 'white'}",
],
)
def test_css_invalid(self, testdir, recwarn, files):
testdir.makepyfile("def test_pass(): pass")
result = testdir.runpytest("--html", "report.html", "--css", "style.css")
path = files
if isinstance(files, list):
file1 = files[0]
file2 = files[1]
result = testdir.runpytest(
"--html", "report.html", "--css", file1, "--css", file2
)
else:
result = testdir.runpytest("--html", "report.html", "--css", path)
assert result.ret
assert len(recwarn) == 0
assert "No such file or directory: 'style.css'" in result.stderr.str()
if isinstance(files, list):
assert files[0] in result.stderr.str() and files[1] in result.stderr.str()
else:
assert path in result.stderr.str()

def test_css_invalid_no_html(self, testdir):
testdir.makepyfile("def test_pass(): pass")
Expand Down

0 comments on commit 8b7bdc1

Please sign in to comment.