(pytester)
| 2 | |
| 3 | |
| 4 | def test_steps(pytester): |
| 5 | pytester.makefile( |
| 6 | ".feature", |
| 7 | steps=textwrap.dedent( |
| 8 | """\ |
| 9 | Feature: Steps are executed one by one |
| 10 | Steps are executed one by one. Given and When sections |
| 11 | are not mandatory in some cases. |
| 12 | |
| 13 | Scenario: Executed step by step |
| 14 | Given I have a foo fixture with value "foo" |
| 15 | And there is a list |
| 16 | When I append 1 to the list |
| 17 | And I append 2 to the list |
| 18 | And I append 3 to the list |
| 19 | Then foo should have value "foo" |
| 20 | But the list should be [1, 2, 3] |
| 21 | """ |
| 22 | ), |
| 23 | ) |
| 24 | |
| 25 | pytester.makepyfile( |
| 26 | textwrap.dedent( |
| 27 | """\ |
| 28 | from pytest_bdd import given, when, then, scenario |
| 29 | |
| 30 | @scenario("steps.feature", "Executed step by step") |
| 31 | def test_steps(): |
| 32 | pass |
| 33 | |
| 34 | @given('I have a foo fixture with value "foo"', target_fixture="foo") |
| 35 | def _(): |
| 36 | return "foo" |
| 37 | |
| 38 | |
| 39 | @given("there is a list", target_fixture="results") |
| 40 | def _(): |
| 41 | return [] |
| 42 | |
| 43 | |
| 44 | @when("I append 1 to the list") |
| 45 | def _(results): |
| 46 | results.append(1) |
| 47 | |
| 48 | |
| 49 | @when("I append 2 to the list") |
| 50 | def _(results): |
| 51 | results.append(2) |
| 52 | |
| 53 | |
| 54 | @when("I append 3 to the list") |
| 55 | def _(results): |
| 56 | results.append(3) |
| 57 | |
| 58 | |
| 59 | @then('foo should have value "foo"') |
| 60 | def _(foo): |
| 61 | assert foo == "foo" |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…