-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Deprecation of terminalreporter.writer causes plugin tests to fail. #6936
Comments
Thanks a lot @BeyondEvil! Hmmm this is tricky, the deprecation is happening because (Sorry for the screenshot, I'm short on time). Not sure how to approach this, suggestions are welcome! |
The pytest internals are very much a black box to me. But I do at least want to try and help with a solution (more of a hack maybe). How about adding below snippet in pytester#inline_run. import warnings
from _pytest.warnings import _setoption
arg = "ignore:TerminalReporter.writer:pytest.PytestDeprecationWarning"
_setoption(warnings, arg) I'm happy to do a PR if there's no better solution. |
This will be fixed by #6898, which includes a change to skip the |
Good reminder, I want that sorted soon |
@RonnyPfannschmidt I am looking forwards to see this fixed as it breaking other projects like pytest-html. |
The Bugfix was released |
I'm probably doing something wrong. But the error described in this issue still happens with pytest 5.4.2. @RonnyPfannschmidt |
Then I misunderstood something and a additional fix is needed |
Let me know if there's something I can help with @RonnyPfannschmidt |
Atm anything, currently I don't have much time for pytest due to global reasons |
@BeyondEvil it isn't merged yet, unless I misunderstand. For reference, the issue is this:
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:
|
I agree, but with tongue-in-cheek, I'm sure there's a test suite out there which has a property, that when accessed, returns a function marked as a fixture. 😆 |
Time for a breaking change |
Do you plan to get to this @RonnyPfannschmidt? Otherwise we will just remove the attribute in 6.1. |
I'm going to try and get to it this evening |
Hello all, just chiming in to say we are still seeing this in pytest 5.4.3. Has there been any movement on this? Is there help we can provide? |
I do not get to it @nicoddemus can you pick up the removal? |
Sure, no problem. |
I was about to remove this for 6.0, but then thought it was better to just wait to remove this in 6.1: I don't see much reason to bypass our usual deprecation/removal process. |
I don't know if anyone else is still experiencing this issue, but as far as I can tell it's pretty much exactly what @bluetech said - the issue stems from something in one of the JetBrains plugins trying to access the I have no idea what the "correct" fix is, and I'm personally more willing to patch the plugin than I am to patch the local instance of PyTest, so I came up with this: from typing import Any
from _pytest import compat
def patched_safe_getattr(object: Any, name: str, default: Any) -> Any:
""" PyCharm has a PyTest plugin that *will not* stop
throwing deprecation warnings, pretty much no matter
what you do
So, instead of accepting that as inevitable, we're gonna
monkeypatch the method that trips the deprecation warning
"""
try:
if all(("TerminalReporter".casefold() in str(object).casefold(), name == "writer")):
return getattr(object, "_tw", default)
return getattr(object, name, default)
except compat.TEST_OUTCOME:
return default
compat.safe_getattr = patched_safe_getattr And added it immediately after the pytest imports in:
The deprecation warning doesn't get thrown because the plugin (and everything else that gets loaded, really) is now handed Like I said, it may not be an ideal solution, but it is a functional solution - at least until someone smarter than me comes up with a more proper fix. 😅 |
@the-wondersmith That seems unrelated to plugin tests using pytester/testdir (which this issue is about). That one should probably be reported to JetBrains if that hasn't happened yet. |
I can confirm this is 100% unrelated to JetBrain. |
Apologies for the off topic comment then. It's been a recurring issue for me personally and I'd not been able to find a workable solution for it. |
Just for clarification, the cause is outlined in #6936 (comment): basically when listing all members of We could implement a somewhat convoluted fix to bypass descriptor/properties from that check, but we decided that it is worth introducing this change given that |
Fixed by #7660 |
pin pytes to range until we deal with this: pytest-dev/pytest#6936
After the deprecation of
terminalreporter.writer
pytest plugin tests usingpytester
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.
test outcome
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
The text was updated successfully, but these errors were encountered: