Use safe_getattr() in getfixturemarker()

This commit is contained in:
Jon Parise 2022-04-22 14:38:36 -07:00
parent 0347957aa7
commit e598429c73
1 changed files with 4 additions and 9 deletions

View File

@ -223,15 +223,10 @@ def add_funcarg_pseudo_fixture_def(
def getfixturemarker(obj: object) -> Optional["FixtureFunctionMarker"]: def getfixturemarker(obj: object) -> Optional["FixtureFunctionMarker"]:
"""Return fixturemarker or None if it doesn't exist or raised """Return fixturemarker or None if it doesn't exist or raised
exceptions.""" exceptions."""
try: return cast(
fixturemarker: Optional[FixtureFunctionMarker] = getattr( Optional[FixtureFunctionMarker],
obj, "_pytestfixturefunction", None safe_getattr(obj, "_pytestfixturefunction", None),
) )
except TEST_OUTCOME:
# some objects raise errors like request (from flask import request)
# we don't expect them to be fixture functions
return None
return fixturemarker
# Parametrized fixture key, helper alias for code below. # Parametrized fixture key, helper alias for code below.