Fix buggy fixture discovery.
Items in fixturemanager._arg2fixturedefs are LIFO, not FIFO
This commit is contained in:
parent
b3e0d4ac65
commit
f5aafe594d
|
@ -40,7 +40,7 @@ def find_argumented_step_function(name: str, type_: str, fixturemanager: Fixture
|
||||||
"""Find argumented step fixture name."""
|
"""Find argumented step fixture name."""
|
||||||
# happens to be that _arg2fixturedefs is changed during the iteration so we use a copy
|
# happens to be that _arg2fixturedefs is changed during the iteration so we use a copy
|
||||||
for fixturename, fixturedefs in list(fixturemanager._arg2fixturedefs.items()):
|
for fixturename, fixturedefs in list(fixturemanager._arg2fixturedefs.items()):
|
||||||
for fixturedef in fixturedefs:
|
for fixturedef in reversed(fixturedefs):
|
||||||
step_func_context = getattr(fixturedef.func, "_pytest_bdd_step_context", None)
|
step_func_context = getattr(fixturedef.func, "_pytest_bdd_step_context", None)
|
||||||
if step_func_context is None:
|
if step_func_context is None:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -45,7 +45,7 @@ from typing_extensions import Literal
|
||||||
|
|
||||||
from .parsers import StepParser, get_parser
|
from .parsers import StepParser, get_parser
|
||||||
from .types import GIVEN, THEN, WHEN
|
from .types import GIVEN, THEN, WHEN
|
||||||
from .utils import get_caller_module_locals, setdefault
|
from .utils import get_caller_module_locals
|
||||||
|
|
||||||
TCallable = TypeVar("TCallable", bound=Callable[..., Any])
|
TCallable = TypeVar("TCallable", bound=Callable[..., Any])
|
||||||
|
|
||||||
|
@ -193,7 +193,11 @@ def inject_fixture(request: FixtureRequest, arg: str, value: Any) -> None:
|
||||||
request.addfinalizer(fin)
|
request.addfinalizer(fin)
|
||||||
|
|
||||||
# inject fixture definition
|
# inject fixture definition
|
||||||
request._fixturemanager._arg2fixturedefs.setdefault(arg, []).insert(0, fd)
|
# TODO: This seems wrong, since pytest treats the last elements as the highest priority ones
|
||||||
|
# request._fixturemanager._arg2fixturedefs.setdefault(arg, []).insert(0, fd)
|
||||||
|
# This seems more correct:
|
||||||
|
request._fixturemanager._arg2fixturedefs.setdefault(arg, []).append(fd)
|
||||||
|
|
||||||
# inject fixture value in request cache
|
# inject fixture value in request cache
|
||||||
request._fixture_defs[arg] = fd
|
request._fixture_defs[arg] = fd
|
||||||
if add_fixturename:
|
if add_fixturename:
|
||||||
|
|
Loading…
Reference in New Issue