Closed rib3 closed 5 years ago
Ayyyoooo, danke schön again for the PR suite.
This one I close in favour of #7 because I'd rather choose the proper method once at startup, to avoid adding extra jumps to stack traces (though that's a weak point), and in this particular case, a double call to __getattr__
.
AFAIK, under the hood, hasattr()
is basically implemented as:
def hasattr(o, attr):
try:
getattr(o, attr)
except AttributeError:
return False
else:
return True
So, to avoid an extra call, I might've written the get_closest_marker
method in this PR as:
def get_closest_marker(item, *args, **kwargs):
for attr in 'get_closest_marker', 'get_marker':
try:
meth = getattr(item, attr)
except AttributeError:
continue
else:
return meth(*args, **kwargs)
else:
raise RuntimeError('Unable to determine get_closest_marker method.')
yeah, no problem, there are a few different ways to implement this.
I thought about fetching it once like you ended up doing in #7:
But I figured i should just send it your way so you could decide how you wanted to do it.
Thanks for the pytest plugin!
Cheers, man! I think you made a good call; the PR's existence is 80% of the work. I actually updated #7 after rereading this PR, because simply calling Node.get_closest_marker
would ignore any overrides by subclasses of Node
. So, thank you :P
I released version 1.2.1 on PyPI: https://pypi.org/project/pytest-only/
Holler if you run into any issues
Pytest 4.1 dropped Node.get_marker.
this PR adds a preference to use
get_closest_marker
, otherwise it falls back toget_marker
Alternate to #5