|
12 | 12 | """
|
13 | 13 | from __future__ import annotations
|
14 | 14 |
|
15 |
| -import collections |
16 | 15 | import os
|
17 | 16 | import re
|
18 | 17 | from typing import TYPE_CHECKING, Callable, cast
|
19 | 18 |
|
20 | 19 | import pytest
|
21 |
| -from _pytest.fixtures import FixtureLookupError, FixtureManager, FixtureRequest, call_fixture_func |
| 20 | +from _pytest.fixtures import FixtureManager, FixtureRequest, call_fixture_func |
22 | 21 |
|
23 | 22 | from . import exceptions
|
24 | 23 | from .feature import get_feature, get_features
|
25 |
| -from .steps import StepFunctionContext, get_step_fixture_name, inject_fixture |
| 24 | +from .steps import StepFunctionContext, inject_fixture |
26 | 25 | from .utils import CONFIG_STACK, get_args, get_caller_module_locals, get_caller_module_path
|
27 | 26 |
|
28 | 27 | if TYPE_CHECKING:
|
@@ -54,18 +53,6 @@ def find_argumented_step_function(name: str, type_: str, fixturemanager: Fixture
|
54 | 53 | return None
|
55 | 54 |
|
56 | 55 |
|
57 |
| -def _find_step_function(request: FixtureRequest, step: Step, scenario: Scenario) -> StepFunctionContext: |
58 |
| - """Match the step defined by the parser.""" |
59 |
| - # Could not find a fixture with the same name, let's see if there is a parser involved |
60 |
| - step_func_context = find_argumented_step_function(step.name, step.type, request._fixturemanager) |
61 |
| - if step_func_context is None: |
62 |
| - raise exceptions.StepDefinitionNotFoundError( |
63 |
| - f"Step definition is not found: {step}. " |
64 |
| - f'Line {step.line_number} in scenario "{scenario.name}" in the feature "{scenario.feature.filename}"' |
65 |
| - ) |
66 |
| - return step_func_context |
67 |
| - |
68 |
| - |
69 | 56 | def _execute_step_function(
|
70 | 57 | request: FixtureRequest, scenario: Scenario, step: Step, context: StepFunctionContext
|
71 | 58 | ) -> None:
|
@@ -120,13 +107,17 @@ def _execute_scenario(feature: Feature, scenario: Scenario, request: FixtureRequ
|
120 | 107 | request.config.hook.pytest_bdd_before_scenario(request=request, feature=feature, scenario=scenario)
|
121 | 108 |
|
122 | 109 | for step in scenario.steps:
|
123 |
| - try: |
124 |
| - step_func_context = _find_step_function(request, step, scenario) |
125 |
| - except exceptions.StepDefinitionNotFoundError as exception: |
| 110 | + context = find_argumented_step_function(step.name, step.type, request._fixturemanager) |
| 111 | + if context is None: |
| 112 | + exc = exceptions.StepDefinitionNotFoundError( |
| 113 | + f"Step definition is not found: {step}. " |
| 114 | + f'Line {step.line_number} in scenario "{scenario.name}" in the feature "{scenario.feature.filename}"' |
| 115 | + ) |
126 | 116 | request.config.hook.pytest_bdd_step_func_lookup_error(
|
127 |
| - request=request, feature=feature, scenario=scenario, step=step, exception=exception |
| 117 | + request=request, feature=feature, scenario=scenario, step=step, exception=exc |
128 | 118 | )
|
129 |
| - raise |
| 119 | + raise exc |
| 120 | + step_func_context = context |
130 | 121 |
|
131 | 122 | try:
|
132 | 123 | _execute_step_function(request, scenario, step, step_func_context)
|
|
0 commit comments