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"]:
"""Return fixturemarker or None if it doesn't exist or raised
exceptions."""
try:
fixturemarker: Optional[FixtureFunctionMarker] = 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
return cast(
Optional[FixtureFunctionMarker],
safe_getattr(obj, "_pytestfixturefunction", None),
)
# Parametrized fixture key, helper alias for code below.