Test step arguments in when steps.
(pytester)
| 58 | |
| 59 | |
| 60 | def test_argument_in_when(pytester): |
| 61 | """Test step arguments in when steps.""" |
| 62 | pytester.makefile( |
| 63 | ".feature", |
| 64 | arguments=textwrap.dedent( |
| 65 | """\ |
| 66 | Feature: Step arguments |
| 67 | Scenario: Argument in when |
| 68 | Given I have an argument 1 |
| 69 | When I get argument 5 |
| 70 | Then My argument should be 5 |
| 71 | """ |
| 72 | ), |
| 73 | ) |
| 74 | |
| 75 | pytester.makepyfile( |
| 76 | textwrap.dedent( |
| 77 | """\ |
| 78 | import pytest |
| 79 | from pytest_bdd import parsers, given, when, then, scenario |
| 80 | |
| 81 | @scenario("arguments.feature", "Argument in when") |
| 82 | def test_arguments(): |
| 83 | pass |
| 84 | |
| 85 | |
| 86 | @pytest.fixture |
| 87 | def arguments(): |
| 88 | return dict() |
| 89 | |
| 90 | |
| 91 | @given(parsers.cfparse("I have an argument {arg:Number}", extra_types=dict(Number=int))) |
| 92 | def _(arguments, arg): |
| 93 | arguments["arg"] = arg |
| 94 | |
| 95 | |
| 96 | @when(parsers.cfparse("I get argument {arg:d}")) |
| 97 | def _(arguments, arg): |
| 98 | arguments["arg"] = arg |
| 99 | |
| 100 | |
| 101 | @then(parsers.cfparse("My argument should be {arg:d}")) |
| 102 | def _(arguments, arg): |
| 103 | assert arguments["arg"] == arg |
| 104 | |
| 105 | """ |
| 106 | ) |
| 107 | ) |
| 108 | result = pytester.runpytest() |
| 109 | result.assert_outcomes(passed=1) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…