diff --git a/Features/Step definition/Parameters/Injection as fixtures.feature b/Features/Step definition/Parameters/Injection as fixtures.feature index 0c1fb213..c5a34df8 100644 --- a/Features/Step definition/Parameters/Injection as fixtures.feature +++ b/Features/Step definition/Parameters/Injection as fixtures.feature @@ -86,11 +86,11 @@ Feature: Step definitions parameters injection as fixtures """python import pytest from pytest_bdd import scenario - + from pytest_bdd.compatibility.pytest import FixtureLookupError @scenario("Freshness.feature") def test_passing_feature(request, cuke_taste): assert cuke_taste == 'salted' - with pytest.raises(pytest.FixtureLookupError): + with pytest.raises(FixtureLookupError): request.getfixturevalue('freshness') """ When run pytest @@ -127,11 +127,12 @@ Feature: Step definitions parameters injection as fixtures """python import pytest from pytest_bdd import scenario + from pytest_bdd.compatibility.pytest import FixtureLookupError @scenario("Freshness.feature") def test_passing_feature(request, cuke_taste): assert cuke_taste == 'salted' - with pytest.raises(pytest.FixtureLookupError): + with pytest.raises(FixtureLookupError): request.getfixturevalue('freshness') """ When run pytest @@ -160,11 +161,12 @@ Feature: Step definitions parameters injection as fixtures """python import pytest from pytest_bdd import scenario + from pytest_bdd.compatibility.pytest import FixtureLookupError @scenario("Freshness.feature") def test_passing_feature(request, freshness): assert freshness == 'salted' - with pytest.raises(pytest.FixtureLookupError): + with pytest.raises(FixtureLookupError): request.getfixturevalue('age') """ When run pytest diff --git a/Features/Steps to step definition bounding.feature b/Features/Steps to step definition bounding.feature index 2b445612..66e051e7 100644 --- a/Features/Steps to step definition bounding.feature +++ b/Features/Steps to step definition bounding.feature @@ -22,7 +22,6 @@ Feature: Gherkin steps bounding to steps definitions And File "conftest.py" with content: """python from pytest_bdd import given, when, then, step - from cucumber_messages import DataTable from pytest import fixture # pytest fixtures could be used from step definitions, so some @@ -54,7 +53,7 @@ Feature: Gherkin steps bounding to steps definitions @then('there are passed steps by kind:') def check_step_counter(step, step_counter): # Step datatables data could be accessed in the next manner - step_data_table: DataTable = step.data_table + step_data_table = step.data_table oracle_results_header = [cell.value for cell in step_data_table.rows[0].cells] oracle_results_values = [int(cell.value) for cell in step_data_table.rows[1].cells] oracle_result = dict(zip(oracle_results_header, oracle_results_values)) diff --git a/src/pytest_bdd/steps.py b/src/pytest_bdd/steps.py index 52ec67b2..5ec9faef 100644 --- a/src/pytest_bdd/steps.py +++ b/src/pytest_bdd/steps.py @@ -37,7 +37,21 @@ def given_beautiful_article(article): import warnings from contextlib import suppress from inspect import getfile, getsourcelines -from typing import Any, Callable, Collection, Dict, Iterable, Iterator, Mapping, Optional, Sequence, Set, Union, cast +from typing import ( + Any, + Callable, + Collection, + Dict, + Iterable, + Iterator, + Mapping, + Optional, + Sequence, + Set, + Type, + Union, + cast, +) from uuid import uuid4 from warnings import warn @@ -51,7 +65,7 @@ def given_beautiful_article(article): from messages import PickleStep as Step # type:ignore[attr-defined] from messages import SourceReference, StepDefinition, StepDefinitionPattern # type:ignore[attr-defined] from pytest_bdd.compatibility.path import relpath -from pytest_bdd.compatibility.pytest import Config, Parser, TypeAlias, get_config_root_path +from pytest_bdd.compatibility.pytest import Config, FixtureLookupError, Parser, TypeAlias, get_config_root_path from pytest_bdd.model import Feature, StepType from pytest_bdd.model.messages_extension import ExpressionType as ExpressionTypeExtension from pytest_bdd.parsers import StepParser @@ -351,7 +365,7 @@ class Definition: anonymous_group_names: Optional[Collection[str]] = attrib() converters: Dict[str, Callable] = attrib() params_fixtures_mapping: Union[ # type: ignore[valid-type] - Collection[str], Mapping[Union[str, type[Ellipsis]], Union[str, type[Ellipsis], None]], Any + Collection[str], Mapping[Union[str, Any], Union[str, Any, None]], Any ] = attrib() param_defaults: dict = attrib() target_fixtures: Sequence[str] = attrib() @@ -464,7 +478,7 @@ def inject_registry_fixture_and_register_steps(cls, obj): def _(request): try: return request.getfixturevalue(fixture_name) - except pytest.FixtureLookupError: + except FixtureLookupError: ... setdefaultattr(obj, fixture_name, value_factory=lambda: (_)) diff --git a/src/pytest_bdd/testing_utils.py b/src/pytest_bdd/testing_utils.py index b9f229e4..d991de5c 100644 --- a/src/pytest_bdd/testing_utils.py +++ b/src/pytest_bdd/testing_utils.py @@ -1,14 +1,15 @@ from functools import partial from itertools import islice from operator import attrgetter -from typing import Optional - -from cucumber_messages import DataTable +from typing import TYPE_CHECKING, Optional from pytest_bdd.utils import compose +if TYPE_CHECKING: # pragma: no cover + from cucumber_messages import DataTable + -def data_table_to_dicts(data_table: Optional[DataTable]): +def data_table_to_dicts(data_table: Optional["DataTable"]): if data_table is None: return {}