From 36fc3e19000dcb8c10f034a687f7ef8e845cd51f Mon Sep 17 00:00:00 2001 From: Krzysztof Pawlik Date: Thu, 12 Sep 2019 14:17:54 +0200 Subject: [PATCH 1/4] Close opened resource. --- pytest_html/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_html/plugin.py b/pytest_html/plugin.py index 7e14df5d..0a286a0e 100644 --- a/pytest_html/plugin.py +++ b/pytest_html/plugin.py @@ -68,7 +68,7 @@ def pytest_configure(config): htmlpath = config.getoption("htmlpath") if htmlpath: for csspath in config.getoption("css"): - open(csspath) + open(csspath).close() if not hasattr(config, "slaveinput"): # prevent opening htmlpath on slave nodes (xdist) config._html = HTMLReport(htmlpath, config) From cef8577d8e2721d56b3d6a08d12c2876f961af7b Mon Sep 17 00:00:00 2001 From: Krzysztof Pawlik <41990220+krzysztof-pawlik-gat@users.noreply.github.com> Date: Fri, 13 Sep 2019 08:29:57 +0200 Subject: [PATCH 2/4] Update pytest_html/plugin.py Co-Authored-By: Bruno Rocha --- pytest_html/plugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytest_html/plugin.py b/pytest_html/plugin.py index 0a286a0e..3c353b5e 100644 --- a/pytest_html/plugin.py +++ b/pytest_html/plugin.py @@ -68,7 +68,8 @@ def pytest_configure(config): htmlpath = config.getoption("htmlpath") if htmlpath: for csspath in config.getoption("css"): - open(csspath).close() + if not os.path.exists(csspath): + raise IOError("No such file or directory: '{}'".format(csspath)) if not hasattr(config, "slaveinput"): # prevent opening htmlpath on slave nodes (xdist) config._html = HTMLReport(htmlpath, config) From ed9eb4d2ea4167d37d355db460c9512ac742bb21 Mon Sep 17 00:00:00 2001 From: Krzysztof Pawlik Date: Fri, 13 Sep 2019 08:31:12 +0200 Subject: [PATCH 3/4] Use `f""` instead of `.format()` call. --- pytest_html/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_html/plugin.py b/pytest_html/plugin.py index 3c353b5e..bd9ecb6f 100644 --- a/pytest_html/plugin.py +++ b/pytest_html/plugin.py @@ -69,7 +69,7 @@ def pytest_configure(config): if htmlpath: for csspath in config.getoption("css"): if not os.path.exists(csspath): - raise IOError("No such file or directory: '{}'".format(csspath)) + raise IOError(f"No such file or directory: '{csspath}'") if not hasattr(config, "slaveinput"): # prevent opening htmlpath on slave nodes (xdist) config._html = HTMLReport(htmlpath, config) From 05ac9a83fe7cb9160bf420927603e61f68692950 Mon Sep 17 00:00:00 2001 From: Krzysztof Pawlik Date: Tue, 17 Sep 2019 09:18:25 +0200 Subject: [PATCH 4/4] Add validation for raised warnings to tests. --- testing/test_pytest_html.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/test_pytest_html.py b/testing/test_pytest_html.py index 1fe847e6..c05b0615 100644 --- a/testing/test_pytest_html.py +++ b/testing/test_pytest_html.py @@ -759,7 +759,7 @@ def test_pass(): pass assert re.search(regex_error, html) is not None @pytest.mark.parametrize("colors", [(["red"]), (["green", "blue"])]) - def test_css(self, testdir, colors): + def test_css(self, testdir, recwarn, colors): testdir.makepyfile("def test_pass(): pass") css = {} cssargs = [] @@ -770,14 +770,16 @@ def test_css(self, testdir, colors): cssargs.extend(["--css", path]) result, html = run(testdir, "report.html", "--self-contained-html", *cssargs) assert result.ret == 0 + assert len(recwarn) == 0 for k, v in css.items(): assert str(v["path"]) in html assert v["style"] in html - def test_css_invalid(self, testdir): + def test_css_invalid(self, testdir, recwarn): testdir.makepyfile("def test_pass(): pass") result = testdir.runpytest("--html", "report.html", "--css", "style.css") assert result.ret + assert len(recwarn) == 0 assert "No such file or directory: 'style.css'" in result.stderr.str() def test_css_invalid_no_html(self, testdir):