Deprecation of terminalreporter.writer causes plugin tests to fail.
See original GitHub issueAfter 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:
- Created 4 years ago
- Reactions:8
- Comments:26 (18 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m going to try and get to it this evening
@BeyondEvil it isn’t merged yet, unless I misunderstand.
For reference, the issue is this:
TerminalReporter
has an propertywriter
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 withgetattr
and checking if they are fixtures. If the attribute is a property, its actually runs, and inwriter
s 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: