Skip to content
Draft
Changes from 1 commit
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
Next Next commit
fix fixture lookup triggering the TerminalWriter.writer deprecation
  • Loading branch information
RonnyPfannschmidt committed Aug 2, 2020
commit 1f99a3ebab11a40d9c0d900698348814c9605b90
5 changes: 5 additions & 0 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,11 @@ def parsefactories(
for name in dir(holderobj):
# The attribute can be an arbitrary descriptor, so the attribute
# access below can raise. safe_getatt() ignores such exceptions.
# additionally properties are ignored by default to avoid triggering warnings
Copy link
Member

Choose a reason for hiding this comment

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

For reference, the safe_getattr() and comment above was added in 3a0a0c2 to fix #2234. There I wrote

A better solution would be to completely skip access to all custom descriptors, such that the offending code doesn't even trigger. However I think this requires manually going through the instance and all of its MRO for each and every attribute checking if it might be a proper fixture before accessing it. So I took the easy route here.

So this at least seems to be a step in the right direction. But this was a long time ago.

There's a question if this is any backward compatibility concern here. Is it possible in any way to use a property as a fixture? (I'm not familiar with this code yet).

In any case I think it would be to discuss this change in a separate PR so it can be considered properly.

Copy link
Member Author

Choose a reason for hiding this comment

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

as a breaking change its ok to drop consideration for properties

as methods are descriptors, we cant drop everything

i would prefer if we could set up better separation for fixture lokup

if not isinstance(holderobj, type) and isinstance(
safe_getattr(holderobj.__class__, name, None), property
):
continue
obj = safe_getattr(holderobj, name, None)
marker = getfixturemarker(obj)
if not isinstance(marker, FixtureFunctionMarker):
Expand Down