Skip to content

Commit

Permalink
Fixup import
Browse files Browse the repository at this point in the history
  • Loading branch information
elchupanebrej committed Oct 5, 2024
1 parent 2128bae commit e80645b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Features/Steps to step definition bounding.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
22 changes: 18 additions & 4 deletions src/pytest_bdd/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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: (_))
Expand Down
9 changes: 5 additions & 4 deletions src/pytest_bdd/testing_utils.py
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down

0 comments on commit e80645b

Please sign in to comment.