Skip to content

Better fix for TerminalReporter issue #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@
pytest_plugins = ("pytester",)


def handle_tr_writer_deprecation():
# Remove this function when they've fixed
def remove_deprecation_from_recwarn(recwarn):
# TODO: Temporary hack until they fix
# https://github.com/pytest-dev/pytest/issues/6936
import warnings
from _pytest.warnings import _setoption

arg = "ignore:TerminalReporter.writer:pytest.PytestDeprecationWarning"
_setoption(warnings, arg)
return [
item for item in recwarn if "TerminalReporter.writer" not in repr(item.message)
]


def run(testdir, path="report.html", *args):
# TODO: Temporary hack until they fix
# https://github.com/pytest-dev/pytest/issues/6936
handle_tr_writer_deprecation() # TODO: Temporary hack
path = testdir.tmpdir.join(path)
result = testdir.runpytest("--html", path, *args)
return result, read_html(path)
Expand Down Expand Up @@ -232,9 +227,6 @@ def test_report_title(self, testdir, path):
assert report_title in html

def test_report_title_addopts_env_var(self, testdir, monkeypatch):
# TODO: Temporary hack until they fix
# https://github.com/pytest-dev/pytest/issues/6936
handle_tr_writer_deprecation()
report_location = "REPORT_LOCATION"
report_name = "MuhReport"
monkeypatch.setenv(report_location, report_name)
Expand Down Expand Up @@ -881,7 +873,8 @@ def test_css(self, testdir, recwarn, colors):
cssargs.extend(["--css", path])
result, html = run(testdir, "report.html", "--self-contained-html", *cssargs)
assert result.ret == 0
assert len(recwarn) == 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
Expand All @@ -894,9 +887,6 @@ def test_css_invalid(self, testdir, recwarn):
assert "No such file or directory: 'style.css'" in result.stderr.str()

def test_css_invalid_no_html(self, testdir):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mark the tests to filter warnings:

@pytest.mark.filterwarnings("ignore:.*TerminalReporter.writer.*")

You might not need remove_deprecation_from_recwarn in the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it and it didn't work @nicoddemus

Maybe I'm doing something wrong?

    @pytest.mark.filterwarnings("ignore:.*TerminalReporter.writer.*")
    @pytest.mark.parametrize("colors", [(["red"]), (["green", "blue"])])
    def test_css(self, testdir, recwarn, colors):
        testdir.makepyfile("def test_pass(): pass")
        css = {}
        cssargs = []
        for color in colors:
            style = f"* {{color: {color}}}"
            path = testdir.makefile(".css", **{color: style})
            css[color] = {"style": style, "path": path}
            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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah unfortunately the mark is considered only for the test run, not the setup (which is where the warning is issued).

# TODO: Temporary hack until they fix
# https://github.com/pytest-dev/pytest/issues/6936
handle_tr_writer_deprecation()
testdir.makepyfile("def test_pass(): pass")
result = testdir.runpytest("--css", "style.css")
assert result.ret == 0
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ exclude = .eggs,.tox

[pytest]
testpaths = testing
# TODO: Temporary hack until they fix
# https://github.com/pytest-dev/pytest/issues/6936
filterwarnings =
ignore:.*TerminalReporter.writer attribute is deprecated.*:pytest.PytestDeprecationWarning