Skip to content

Commit 7166364

Browse files
Krzysztof PawlikBeyondEvil
authored andcommitted
Close opened resource. (#235)
* Close opened resource. * Update pytest_html/plugin.py Co-Authored-By: Bruno Rocha <[email protected]> * Use `f""` instead of `.format()` call. * Add validation for raised warnings to tests.
1 parent 0fa73c2 commit 7166364

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pytest_html/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def pytest_configure(config):
6868
htmlpath = config.getoption("htmlpath")
6969
if htmlpath:
7070
for csspath in config.getoption("css"):
71-
open(csspath)
71+
if not os.path.exists(csspath):
72+
raise IOError(f"No such file or directory: '{csspath}'")
7273
if not hasattr(config, "slaveinput"):
7374
# prevent opening htmlpath on slave nodes (xdist)
7475
config._html = HTMLReport(htmlpath, config)

testing/test_pytest_html.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def test_pass(): pass
759759
assert re.search(regex_error, html) is not None
760760

761761
@pytest.mark.parametrize("colors", [(["red"]), (["green", "blue"])])
762-
def test_css(self, testdir, colors):
762+
def test_css(self, testdir, recwarn, colors):
763763
testdir.makepyfile("def test_pass(): pass")
764764
css = {}
765765
cssargs = []
@@ -770,14 +770,16 @@ def test_css(self, testdir, colors):
770770
cssargs.extend(["--css", path])
771771
result, html = run(testdir, "report.html", "--self-contained-html", *cssargs)
772772
assert result.ret == 0
773+
assert len(recwarn) == 0
773774
for k, v in css.items():
774775
assert str(v["path"]) in html
775776
assert v["style"] in html
776777

777-
def test_css_invalid(self, testdir):
778+
def test_css_invalid(self, testdir, recwarn):
778779
testdir.makepyfile("def test_pass(): pass")
779780
result = testdir.runpytest("--html", "report.html", "--css", "style.css")
780781
assert result.ret
782+
assert len(recwarn) == 0
781783
assert "No such file or directory: 'style.css'" in result.stderr.str()
782784

783785
def test_css_invalid_no_html(self, testdir):

0 commit comments

Comments
 (0)