Add is_pseudo & Replace the bad expression with isinstance check
This commit is contained in:
parent
fc92f9f1dd
commit
0c163ec969
|
@ -882,7 +882,6 @@ def _eval_scope_callable(
|
|||
return result
|
||||
|
||||
|
||||
@final
|
||||
class FixtureDef(Generic[FixtureValue]):
|
||||
"""A container for a fixture definition.
|
||||
|
||||
|
@ -1025,6 +1024,24 @@ class FixtureDef(Generic[FixtureValue]):
|
|||
)
|
||||
|
||||
|
||||
class IdentityFixture(FixtureDef[FixtureValue]):
|
||||
def __init__(
|
||||
self,
|
||||
fixturemanager: "FixtureManager",
|
||||
argname: str,
|
||||
scope: Union[Scope, _ScopeName, Callable[[str, Config], _ScopeName], None],
|
||||
):
|
||||
super().__init__(
|
||||
fixturemanager,
|
||||
"",
|
||||
argname,
|
||||
lambda request: request.param,
|
||||
scope,
|
||||
None,
|
||||
_ispytest=True,
|
||||
)
|
||||
|
||||
|
||||
def resolve_fixture_function(
|
||||
fixturedef: FixtureDef[FixtureValue], request: FixtureRequest
|
||||
) -> "_FixtureFunc[FixtureValue]":
|
||||
|
@ -1488,10 +1505,7 @@ class FixtureManager:
|
|||
arg2fixturedefs[argname] = fixturedefs
|
||||
else:
|
||||
fixturedefs = arg2fixturedefs[argname]
|
||||
if fixturedefs and not (
|
||||
fixturedefs[-1].func.__name__ == "get_direct_param_fixture_func"
|
||||
and fixturedefs[-1].baseid == ""
|
||||
):
|
||||
if fixturedefs and not isinstance(fixturedefs[-1], IdentityFixture):
|
||||
fixturenames_closure = deduplicate_names(
|
||||
fixturenames_closure + arg2fixturedefs[argname][-1].argnames
|
||||
)
|
||||
|
|
|
@ -60,9 +60,9 @@ from _pytest.deprecated import INSTANCE_COLLECTOR
|
|||
from _pytest.deprecated import NOSE_SUPPORT_METHOD
|
||||
from _pytest.fixtures import _get_direct_parametrize_args
|
||||
from _pytest.fixtures import FixtureDef
|
||||
from _pytest.fixtures import FixtureRequest
|
||||
from _pytest.fixtures import FuncFixtureInfo
|
||||
from _pytest.fixtures import get_scope_node
|
||||
from _pytest.fixtures import IdentityFixture
|
||||
from _pytest.main import Session
|
||||
from _pytest.mark import MARK_GEN
|
||||
from _pytest.mark import ParameterSet
|
||||
|
@ -1184,10 +1184,6 @@ class CallSpec2:
|
|||
return "-".join(self._idlist)
|
||||
|
||||
|
||||
def get_direct_param_fixture_func(request: FixtureRequest) -> Any:
|
||||
return request.param
|
||||
|
||||
|
||||
# Used for storing pseudo fixturedefs for direct parametrization.
|
||||
name2pseudofixturedef_key = StashKey[Dict[str, FixtureDef[Any]]]()
|
||||
|
||||
|
@ -1387,16 +1383,8 @@ class Metafunc:
|
|||
if name2pseudofixturedef is not None and argname in name2pseudofixturedef:
|
||||
fixturedef = name2pseudofixturedef[argname]
|
||||
else:
|
||||
fixturedef = FixtureDef(
|
||||
fixturemanager=self.definition.session._fixturemanager,
|
||||
baseid="",
|
||||
argname=argname,
|
||||
func=get_direct_param_fixture_func,
|
||||
scope=scope_,
|
||||
params=None,
|
||||
unittest=False,
|
||||
ids=None,
|
||||
_ispytest=True,
|
||||
fixturedef = IdentityFixture(
|
||||
self.definition.session._fixturemanager, argname, scope_
|
||||
)
|
||||
if name2pseudofixturedef is not None:
|
||||
name2pseudofixturedef[argname] = fixturedef
|
||||
|
|
Loading…
Reference in New Issue