Skip to content

Commit 2fb5a11

Browse files
committed
Updating the docs
1 parent 437bb63 commit 2fb5a11

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

README.rst

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ for `cfparse` parser
210210
@given(
211211
parsers.cfparse("there are {start:Number} cucumbers",
212212
extra_types=dict(Number=int)),
213-
target_fixture="start_cucumbers",
213+
target_fixture="cucumbers",
214214
)
215-
def start_cucumbers(start):
215+
def given_cucumbers(start):
216216
return dict(start=start, eat=0)
217217
218218
for `re` parser
@@ -224,9 +224,9 @@ for `re` parser
224224
@given(
225225
parsers.re(r"there are (?P<start>\d+) cucumbers"),
226226
converters=dict(start=int),
227-
target_fixture="start_cucumbers",
227+
target_fixture="cucumbers",
228228
)
229-
def start_cucumbers(start):
229+
def given_cucumbers(start):
230230
return dict(start=start, eat=0)
231231
232232
@@ -257,20 +257,19 @@ The code will look like:
257257
pass
258258
259259
260-
@given(parsers.parse("there are {start:d} cucumbers"), target_fixture="start_cucumbers")
261-
def start_cucumbers(start):
260+
@given(parsers.parse("there are {start:d} cucumbers"), target_fixture="cucumbers")
261+
def given_cucumbers(start):
262262
return dict(start=start, eat=0)
263263
264264
265265
@when(parsers.parse("I eat {eat:d} cucumbers"))
266-
def eat_cucumbers(start_cucumbers, eat):
266+
def eat_cucumbers(cucumbers, eat):
267267
start_cucumbers["eat"] += eat
268268
269269
270270
@then(parsers.parse("I should have {left:d} cucumbers"))
271-
def should_have_left_cucumbers(start_cucumbers, start, left):
272-
assert start_cucumbers['start'] == start
273-
assert start - start_cucumbers['eat'] == left
271+
def should_have_left_cucumbers(cucumbers, left):
272+
assert cucumbers['start'] - cucumbers['eat'] == left
274273
275274
Example code also shows possibility to pass argument converters which may be useful if you need to postprocess step
276275
arguments after the parser.
@@ -303,21 +302,11 @@ You can implement your own step parser. It's interface is quite simple. The code
303302
return bool(self.regex.match(name))
304303
305304
306-
@given(parsers.parse("there are %start% cucumbers"), target_fixture="start_cucumbers")
307-
def start_cucumbers(start):
305+
@given(parsers.parse("there are %start% cucumbers"), target_fixture="cucumbers")
306+
def given_cucumbers(start):
308307
return dict(start=start, eat=0)
309308
310309
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-
321310
Override fixtures via given steps
322311
---------------------------------
323312

0 commit comments

Comments
 (0)