diff --git a/CHANGES.rst b/CHANGES.rst index 7e4c8de..0520e0c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,20 @@ Release Notes ------------- +**1.22.1 (2019-10-05)** + +* Properly check for presence of CSS file. (`#246 `_) + + * Thanks to `@wanam `_ for reporting, and `@krzysztof-pawlik-gat `_ for the fix + +* Added support for UTF-8 display. (`#244 `_) + + * Thanks to `@Izhu666 `_ for the PR + +* Fix initial sort on column. (`#247 `_) + + * Thanks to `@wanam `_ for reporting and fixing + **1.22.0 (2019-08-06)** * Refactor assets naming to be more readable and OS safe. diff --git a/pytest_html/plugin.py b/pytest_html/plugin.py index 49578cb..facb9e8 100644 --- a/pytest_html/plugin.py +++ b/pytest_html/plugin.py @@ -79,7 +79,10 @@ def pytest_configure(config): htmlpath = config.getoption("htmlpath") if htmlpath: for csspath in config.getoption("css"): - open(csspath) + if not os.path.exists(csspath): + raise IOError( + "No such file or directory: '{csspath}'".format(csspath=csspath) + ) if not hasattr(config, "slaveinput"): # prevent opening htmlpath on slave nodes (xdist) config._html = HTMLReport(htmlpath, config) @@ -114,7 +117,7 @@ class HTMLReport(object): class TestResult: def __init__(self, outcome, report, logfile, config): - self.test_id = report.nodeid + self.test_id = report.nodeid.encode("utf-8").decode("unicode_escape") if getattr(report, "when", "call") != "call": self.test_id = "::".join([report.nodeid, report.when]) self.time = getattr(report, "duration", 0.0) diff --git a/pytest_html/resources/main.js b/pytest_html/resources/main.js index 63e04ba..5d49dbf 100644 --- a/pytest_html/resources/main.js +++ b/pytest_html/resources/main.js @@ -111,7 +111,7 @@ function init () { show_filters(); - toggle_sort_states(find('.initial-sort')); + sort_column(find('.initial-sort')); find_all('.sortable').forEach(function(elem) { elem.addEventListener("click", diff --git a/testing/test_pytest_html.py b/testing/test_pytest_html.py index c7309a4..2dd1a8d 100644 --- a/testing/test_pytest_html.py +++ b/testing/test_pytest_html.py @@ -1,3 +1,4 @@ +# coding: utf-8 # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -816,7 +817,7 @@ class TestHTML: 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 = [] @@ -827,17 +828,33 @@ class TestHTML: 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): testdir.makepyfile("def test_pass(): pass") result = testdir.runpytest("--css", "style.css") assert result.ret == 0 + + def test_report_display_utf8(self, testdir): + testdir.makepyfile( + """ + # coding: utf-8 + import pytest + @pytest.mark.parametrize("utf8", [("测试用例名称")]) + def test_pass(utf8): + assert True + """ + ) + result, html = run(testdir) + assert result.ret == 0 + assert r"\u6d4b\u8bd5\u7528\u4f8b\u540d\u79f0" not in html