4
4
5
5
from pytest_bdd .utils import collect_dumped_objects
6
6
7
+ STEPS = """\
8
+ from pytest_bdd import given, when, then, parsers
9
+ from pytest_bdd.utils import dump_obj
7
10
8
- def test_scenario_with_empty_example_values (pytester ):
9
- pytester .makefile (
10
- ".feature" ,
11
- outline = textwrap .dedent (
12
- """\
13
- Feature: Outline
14
- Scenario Outline: Outlined with empty example values
15
- Given there are <start> cucumbers
16
- When I eat <eat> cucumbers
17
- Then I should have <left> cucumbers
11
+ # Using `parsers.re` so that we can match empty values
18
12
19
- Examples:
20
- | start | eat | left |
21
- | # | | |
22
- """
23
- ),
24
- )
25
- pytester .makeconftest (
26
- textwrap .dedent (
27
- """\
28
- from pytest_bdd import given, when, then, parsers
29
- from pytest_bdd.utils import dump_obj
13
+ @given(parsers.re("there are (?P<start>.*?) cucumbers"))
14
+ def _(start):
15
+ dump_obj(start)
30
16
31
- # Using `parsers.re` so that we can match empty values
32
17
33
- @given (parsers.re("there are (?P<start >.*?) cucumbers"))
34
- def _(start ):
35
- dump_obj(start )
18
+ @when (parsers.re("I eat (?P<eat >.*?) cucumbers"))
19
+ def _(eat ):
20
+ dump_obj(eat )
36
21
37
22
38
- @when (parsers.re("I eat (?P<eat >.*?) cucumbers"))
39
- def _(eat ):
40
- dump_obj(eat )
23
+ @then (parsers.re("I should have (?P<left >.*?) cucumbers"))
24
+ def _(left ):
25
+ dump_obj(left )
41
26
27
+ """
42
28
43
- @then(parsers.re("I should have (?P<left>.*?) cucumbers"))
44
- def _(left):
45
- dump_obj(left)
46
-
47
- """
48
- )
49
- )
50
29
51
- pytester .makepyfile (
52
- textwrap .dedent (
53
- """\
54
- from pytest_bdd import scenario
55
-
56
- @scenario("outline.feature", "Outlined with empty example values")
57
- def test_outline():
58
- pass
59
- """
60
- )
61
- )
62
- result = pytester .runpytest ("-s" )
63
- result .assert_outcomes (passed = 1 )
64
- assert collect_dumped_objects (result ) == ["#" , "" , "" ]
65
-
66
-
67
- def test_scenario_with_empty_example_values_none_transformer (pytester ):
68
- """
69
- Checks that `parsers.re` can transform empty values to None with a converter.
70
- `parsers.parse` and `parsers.cfparse` won't work out of the box this way as they will fail to match the steps.
71
- """
30
+ def test_scenario_with_empty_example_values (pytester ):
72
31
pytester .makefile (
73
32
".feature" ,
74
33
outline = textwrap .dedent (
75
34
"""\
76
35
Feature: Outline
77
- Scenario Outline: Outlined with empty example values and transformer
36
+ Scenario Outline: Outlined with empty example values
78
37
Given there are <start> cucumbers
79
38
When I eat <eat> cucumbers
80
39
Then I should have <left> cucumbers
@@ -85,46 +44,21 @@ def test_scenario_with_empty_example_values_none_transformer(pytester):
85
44
"""
86
45
),
87
46
)
88
- pytester .makeconftest (
89
- textwrap .dedent (
90
- """\
91
- from pytest_bdd import given, when, then, parsers
92
- from pytest_bdd.utils import dump_obj
93
-
94
-
95
- def empty_to_none(value):
96
- return None if value.strip() == "" else value
97
-
98
-
99
- @given(parsers.re("there are (?P<start>.*?) cucumbers"), converters={"start": empty_to_none})
100
- def _(start):
101
- dump_obj(start)
102
-
103
-
104
- @when(parsers.re("I eat (?P<eat>.*?) cucumbers"), converters={"eat": empty_to_none})
105
- def _(eat):
106
- dump_obj(eat)
107
-
108
-
109
- @then(parsers.re("I should have (?P<left>.*?) cucumbers"), converters={"left": empty_to_none})
110
- def _(left):
111
- dump_obj(left)
112
-
113
- """
114
- )
115
- )
47
+ pytester .makeconftest (textwrap .dedent (STEPS ))
116
48
117
49
pytester .makepyfile (
118
50
textwrap .dedent (
119
51
"""\
120
- from pytest_bdd import scenario
52
+ from pytest_bdd.utils import dump_obj
53
+ from pytest_bdd import scenario
54
+ import json
121
55
122
- @scenario("outline.feature", "Outlined with empty example values and transformer ")
123
- def test_outline():
124
- pass
125
- """
56
+ @scenario("outline.feature", "Outlined with empty example values")
57
+ def test_outline():
58
+ pass
59
+ """
126
60
)
127
61
)
128
62
result = pytester .runpytest ("-s" )
129
63
result .assert_outcomes (passed = 1 )
130
- assert collect_dumped_objects (result ) == ["#" , None , None ]
64
+ assert collect_dumped_objects (result ) == ["#" , "" , "" ]
0 commit comments