question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecation of terminalreporter.writer causes plugin tests to fail.

See original GitHub issue

After the deprecation of terminalreporter.writer pytest plugin tests using pytester are getting the deprecation warning, even tho the plugin is not using terminalreporter at all.

Using pytest version 5.3.5 it works as expected.

Tested on both Linux and Mac using the below example test.

pytest_plugins = ("pytester",)

def test_base(testdir, recwarn):
    testdir.makepyfile("def test_pass(): pass")
    testdir.runpytest()
    print(recwarn.list[0])
    assert len(recwarn) == 0
    assert True
test outcome
# pytest -s -ra -v
=========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.7.6, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /pytest-dev/pytest-playground/tests, inifile: pytest.ini
collected 1 item                                                                                                                                                                                           

test_selenium.py::test_base =========================================================================================== test session starts ============================================================================================
platform linux -- Python 3.7.6, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /tmp/pytest-of-root/pytest-5/test_base0
collected 1 item

test_base.py .                                                                                                                                                                                       [100%]

============================================================================================ 1 passed in 0.01s =============================================================================================
{message : PytestDeprecationWarning('TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\nSee https://docs.pytest.org/en/latest/deprecations.html#terminalreporter-writer for more information.'), category : 'PytestDeprecationWarning', filename : '/usr/local/lib/python3.7/site-packages/_pytest/terminal.py', lineno : 289, line : None}
FAILED

================================================================================================= FAILURES =================================================================================================
________________________________________________________________________________________________ test_base _________________________________________________________________________________________________

testdir = <Testdir local('/tmp/pytest-of-root/pytest-5/test_base0')>, recwarn = WarningsRecorder(record=True)

    def test_base(testdir, recwarn):
        testdir.makepyfile("def test_pass(): pass")
        testdir.runpytest()
        print(recwarn.list[0])
>       assert len(recwarn) == 0
E       assert 1 == 0
E         +1
E         -0

/pytest-dev/pytest-playground/tests/test_selenium.py:10: AssertionError
========================================================================================= short test summary info ==========================================================================================
FAILED test_selenium.py::test_base - assert 1 == 0
============================================================================================ 1 failed in 0.18s =============================================================================================

I’m seeing tests fail in pytest-html which only uses terminalreporter.write_sep() in a hook, and in pytest-variables which does not use terminalreporter at all.

It’s failing for both python 3.6 and 3.7. Example

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:26 (18 by maintainers)

github_iconTop GitHub Comments

3reactions
RonnyPfannschmidtcommented, Jun 9, 2020

I’m going to try and get to it this evening

2reactions
bluetechcommented, May 17, 2020

@BeyondEvil it isn’t merged yet, unless I misunderstand.

For reference, the issue is this:

TerminalReporter has an property writer that has been deprecated in pytest 5.4.0. So every time it is accessed, a deprecation warning is triggered.

TerminalReporer is a plugin. A plugin can define fixtures. During the collection phase, pytest collects fixtures by sifting through all attributes of an object (plugin in this case), accessing them with getattr and checking if they are fixtures. If the attribute is a property, its actually runs, and in writers case triggers the warning.

What @RonnyPfannschmidt’s change does is: before probing a given attribute, check if it is a property, and if so, skip it. The change itself is small and can be extracted to its own PR. But before we do so, we should check:

  • Is there some reasonable possibility/use-case for using a property to define a fixture? (probably not)
  • Does the fix adversely impact performance? (probably not)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Deprecations and Removals — pytest documentation
The TerminalReporter.writer attribute has been deprecated and should no longer be used. This was inadvertently exposed as part of the public API of...
Read more >
python - pytest: How to get a list of all failed tests at the end of ...
Run pytest with -rf to get it to print a list of failed tests at the end. From py.test --help : -r chars...
Read more >
Changelog archive — pytest documentation - Read the Docs
#4907: Show XFail reason as part of JUnitXML message field. #5013: Messages from crash reports are displayed within test summaries now, truncated to...
Read more >
pytest Documentation - Read the Docs
How to re-run failed tests and maintain state between test runs . ... “Writing plugins” for managing and writing plugins.
Read more >
Testing in Java & JVM projects - Gradle User Manual
With mergeReruns enabled, tests that pass-on-retry will no longer cause this Jenkins plugin to consider the build to have failed. However, failed test...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found