Skip to content

Commit

Permalink
Slightly simplify examples
Browse files Browse the repository at this point in the history
  • Loading branch information
elchupanebrej committed Jan 13, 2024
1 parent 2dd405b commit 3478ab3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions docs/tutorial/tests/steps/library_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def these_books_in_the_catalog(


@when(
# Step definitions could have parameters. Here could be raw stings, cucumber expressions or regular expressions
re.compile('a (?P<search_type>name|title) search is performed for "(?P<search_term>.+)"'),
target_fixture="search_results",
)
def a_search_type_is_performed_for_search_term(
# `search_results` is a usual pytest fixture defined somewhere else and injected by pytest DI mechanism.
# In this case it will be provided by conftest.py
search_results,
# `search_type` and `search_term` are parameters of this step and is injected by step definition
# `search_type` and `search_term` are parameters of this step and are injected by step definition
search_type: Literal["name", "title"],
search_term: str,
# `catalog` is a fixture injected by another step
Expand All @@ -60,6 +61,12 @@ def a_search_type_is_performed_for_search_term(


@then("only these books will be returned")
def only_these_books_will_be_returned(search_results, step: Step, catalog: Catalog):
def only_these_books_will_be_returned(
# fixtures persist during step execution, so usual context is not required,
# so if you define fixture dependencies debugging becomes much easier.
search_results,
step: Step,
catalog: Catalog,
):
expected_books = get_books_from_data_table(step.data_table)
assert all([book in catalog.storage for book in expected_books])

0 comments on commit 3478ab3

Please sign in to comment.