Merge master with next-gen

This commit is contained in:
Jim Brännlund 2023-04-03 21:54:03 +02:00
commit 5e00bccbde
2 changed files with 34 additions and 54 deletions

View File

@ -6,9 +6,13 @@ Versions follow `Semantic Versioning`_ (``<major>.<minor>.<patch>``).
Version History
---------------
3.2.0 (unreleased)
3.2.0 (2022-10-25)
~~~~~~~~~~~~~~~~~~
* Explicitly add py.xml dependency.
* Thanks to `@smartEBL <https://github.com/smartEBL>`_ for the PR
* Implement the ``visible`` URL query parameter to control visibility of test results on page load. (`#399 <https://github.com/pytest-dev/pytest-html/issues/399>`_)
* Thanks to `@TheCorp <https://github.com/TheCorp>`_ for reporting and `@gnikonorov <https://github.com/gnikonorov>`_ for the fix

View File

@ -1,11 +1,11 @@
# 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/.
import builtins
import json
import os
import random
import re
import sys
from base64 import b64encode
import pkg_resources
@ -13,28 +13,6 @@ import pytest
pytest_plugins = ("pytester",)
if os.name == "nt":
# Force a utf-8 encoding on file io (since by default windows does not). See
# https://github.com/pytest-dev/pytest-html/issues/336
# If we drop support for Python 3.6 and earlier could use python -X utf8 instead.
_real_open = builtins.open
def _open(file, mode="r", buffering=-1, encoding=None, *args, **kwargs):
if mode in ("r", "w") and encoding is None:
encoding = "utf-8"
return _real_open(file, mode, buffering, encoding, *args, **kwargs)
builtins.open = _open
def remove_deprecation_from_recwarn(recwarn):
# TODO: Temporary hack until they fix
# https://github.com/pytest-dev/pytest/issues/6936
return [
item for item in recwarn if "TerminalReporter.writer" not in repr(item.message)
]
def run(testdir, path="report.html", *args):
path = testdir.tmpdir.join(path)
@ -186,7 +164,7 @@ class TestHTML:
assert_results(html, passed=0, failed=1)
assert "AssertionError" in html
@pytest.mark.flaky(reruns=2) # test is flaky on windows
@pytest.mark.skipif(sys.platform == "win32", reason="Test is flaky on Windows")
def test_rerun(self, testdir):
testdir.makeconftest(
"""
@ -972,12 +950,12 @@ class TestHTML:
assert result.ret == 0
assert not re.search(r"\[[\d;]+m", html)
@pytest.mark.parametrize("content", [("'foo'"), ("u'\u0081'")])
@pytest.mark.parametrize("content", ["'foo'", "u'\u0081'"])
def test_utf8_longrepr(self, testdir, content):
testdir.makeconftest(
f"""
import pytest
@pytest.hookimpl(hookwrapper=True)
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
@ -1021,37 +999,35 @@ class TestHTML:
cssargs.extend(["--css", path])
result, html = run(testdir, "report.html", "--self-contained-html", *cssargs)
assert result.ret == 0
warnings = remove_deprecation_from_recwarn(recwarn)
assert len(warnings) == 0
for k, v in css.items():
assert str(v["path"]) in html
assert v["style"] in html
@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")
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
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()
# @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")
# 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
# 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")