You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assert cucumbers['start'] - cucumbers['eat'] == left
274
273
275
274
Example code also shows possibility to pass argument converters which may be useful if you need to postprocess step
276
275
arguments after the parser.
@@ -303,21 +302,11 @@ You can implement your own step parser. It's interface is quite simple. The code
303
302
returnbool(self.regex.match(name))
304
303
305
304
306
-
@given(parsers.parse("there are %start% cucumbers"), target_fixture="start_cucumbers")
307
-
defstart_cucumbers(start):
305
+
@given(parsers.parse("there are %start% cucumbers"), target_fixture="cucumbers")
306
+
defgiven_cucumbers(start):
308
307
returndict(start=start, eat=0)
309
308
310
309
311
-
Step arguments are fixtures as well!
312
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313
-
314
-
Step arguments are injected into pytest `request` context as normal fixtures with the names equal to the names of the
315
-
arguments. This opens a number of possibilities:
316
-
317
-
* you can access step's argument as a fixture in other step function just by mentioning it as an argument (just like any other pytest fixture)
318
-
* if the name of the step argument clashes with existing fixture, it will be overridden by step's argument value; this way you can set/override the value for some fixture deeply inside of the fixture tree in a ad-hoc way by just choosing the proper name for the step argument.
319
-
320
-
321
310
Override fixtures via given steps
322
311
---------------------------------
323
312
@@ -506,7 +495,7 @@ Scenario outlines
506
495
Scenarios can be parametrized to cover few cases. In Gherkin the variable
507
496
templates are written using corner braces as ``<somevalue>``.
508
497
`Gherkin scenario outlines <http://behat.org/en/v3.0/user_guide/writing_scenarios.html#scenario-outlines>`_ are supported by pytest-bdd
509
-
exactly as it's described in bebehave_ docs.
498
+
exactly as it's described in thebehave_ docs.
510
499
511
500
Example:
512
501
@@ -522,121 +511,6 @@ Example:
522
511
| start | eat | left |
523
512
| 12 | 5 | 7 |
524
513
525
-
pytest-bdd feature file format also supports example tables in different way:
526
-
527
-
528
-
.. code-block:: gherkin
529
-
530
-
Feature: Scenario outlines
531
-
Scenario Outline: Outlined given, when, then
532
-
Given there are <start> cucumbers
533
-
When I eat <eat> cucumbers
534
-
Then I should have <left> cucumbers
535
-
536
-
Examples: Vertical
537
-
| start | 12 | 2 |
538
-
| eat | 5 | 1 |
539
-
| left | 7 | 1 |
540
-
541
-
This form allows to have tables with lots of columns keeping the maximum text width predictable without significant
542
-
readability change.
543
-
544
-
The code will look like:
545
-
546
-
.. code-block:: python
547
-
548
-
from pytest_bdd import given, when, then, scenario, parsers
549
-
550
-
551
-
@scenario(
552
-
"outline.feature",
553
-
"Outlined given, when, then",
554
-
)
555
-
deftest_outlined():
556
-
pass
557
-
558
-
559
-
@given(parsers.parse("there are {start:d} cucumbers", target_fixture="start_cucumbers"))
560
-
defstart_cucumbers(start):
561
-
assertisinstance(start, int)
562
-
returndict(start=start)
563
-
564
-
565
-
@when(parsers.parse("I eat {eat:g} cucumbers"))
566
-
defeat_cucumbers(start_cucumbers, eat):
567
-
assertisinstance(eat, float)
568
-
start_cucumbers["eat"] = eat
569
-
570
-
571
-
@then(parsers.parse("I should have {left} cucumbers"))
0 commit comments