Better error on missing CSS files. (#390)
Co-authored-by: Gleb Nikonorov <gleb.i.nikonorov@gmail.com>
This commit is contained in:
parent
817d04df58
commit
8b7bdc1fc5
|
@ -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>`_)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1005,12 +1005,31 @@ class TestHTML:
|
|||
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")
|
||||
|
|
Loading…
Reference in New Issue