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