diff --git a/CHANGES.rst b/CHANGES.rst index 83155e42..b7f5cc5a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,12 @@ Release Notes ------------- +**3.1.1 (unreleased)** + +* Fix issue with reporting of missing CSS files. (`#388 `_) + + * Thanks to `@prakhargurunani `_ for reporting and fixing! + **3.1.0 (2020-12-2)** * Stop attaching test reruns to final test report entries (`#374 `_) diff --git a/src/pytest_html/plugin.py b/src/pytest_html/plugin.py index bec01a74..c01cc7d5 100644 --- a/src/pytest_html/plugin.py +++ b/src/pytest_html/plugin.py @@ -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) diff --git a/testing/test_pytest_html.py b/testing/test_pytest_html.py index 75a8922a..2bab9a19 100644 --- a/testing/test_pytest_html.py +++ b/testing/test_pytest_html.py @@ -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")