Skip to content

Commit 6a2b2fb

Browse files
authored
Merge pull request #749 from pytest-dev/test-feature-description-in-json
Add scenario description to JSON and add test for JSON correctly populating the description from a feature
2 parents be83407 + 02d7c3f commit 6a2b2fb

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Added
1515
Changed
1616
+++++++
1717
* Step arguments ``"datatable"`` and ``"docstring"`` are now reserved, and they can't be used as step argument names.
18+
* Scenario ``description`` field is now set for JSON output
1819

1920
Deprecated
2021
++++++++++

src/pytest_bdd/cucumber_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def stepmap(step: dict[str, Any]) -> dict[str, Any]:
131131
"id": report.item["name"],
132132
"name": scenario["name"],
133133
"line": scenario["line_number"],
134-
"description": "",
134+
"description": scenario["description"],
135135
"tags": self._serialize_tags(scenario),
136136
"type": "scenario",
137137
"steps": [stepmap(step) for step in scenario["steps"]],

src/pytest_bdd/reporting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def serialize(self) -> dict[str, Any]:
113113
"name": scenario.name,
114114
"line_number": scenario.line_number,
115115
"tags": sorted(scenario.tags),
116+
"description": scenario.description,
116117
"feature": {
117118
"keyword": feature.keyword,
118119
"name": feature.name,

tests/feature/test_cucumber_json.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ def test_step_trace(pytester):
5151
"""
5252
@feature-tag
5353
Feature: One passing scenario, one failing scenario
54+
This is a feature description
5455
5556
@scenario-passing-tag
5657
Scenario: Passing
58+
This is a scenario description
59+
5760
Given a passing step
5861
And some other passing step
5962
@@ -116,108 +119,108 @@ def test_passing_outline():
116119
assert result.ret
117120
expected = [
118121
{
119-
"description": "",
122+
"description": "This is a feature description",
120123
"elements": [
121124
{
122-
"description": "",
125+
"description": "This is a scenario description",
123126
"id": "test_passing",
124127
"keyword": "Scenario",
125-
"line": 5,
128+
"line": 6,
126129
"name": "Passing",
127130
"steps": [
128131
{
129132
"keyword": "Given",
130-
"line": 6,
133+
"line": 9,
131134
"match": {"location": ""},
132135
"name": "a passing step",
133136
"result": {"status": "passed", "duration": OfType(int)},
134137
},
135138
{
136139
"keyword": "And",
137-
"line": 7,
140+
"line": 10,
138141
"match": {"location": ""},
139142
"name": "some other passing step",
140143
"result": {"status": "passed", "duration": OfType(int)},
141144
},
142145
],
143-
"tags": [{"name": "scenario-passing-tag", "line": 4}],
146+
"tags": [{"name": "scenario-passing-tag", "line": 5}],
144147
"type": "scenario",
145148
},
146149
{
147150
"description": "",
148151
"id": "test_failing",
149152
"keyword": "Scenario",
150-
"line": 10,
153+
"line": 13,
151154
"name": "Failing",
152155
"steps": [
153156
{
154157
"keyword": "Given",
155-
"line": 11,
158+
"line": 14,
156159
"match": {"location": ""},
157160
"name": "a passing step",
158161
"result": {"status": "passed", "duration": OfType(int)},
159162
},
160163
{
161164
"keyword": "And",
162-
"line": 12,
165+
"line": 15,
163166
"match": {"location": ""},
164167
"name": "a failing step",
165168
"result": {"error_message": OfType(str), "status": "failed", "duration": OfType(int)},
166169
},
167170
],
168-
"tags": [{"name": "scenario-failing-tag", "line": 9}],
171+
"tags": [{"name": "scenario-failing-tag", "line": 12}],
169172
"type": "scenario",
170173
},
171174
{
172175
"description": "",
173176
"keyword": "Scenario Outline",
174-
"tags": [{"line": 14, "name": "scenario-outline-passing-tag"}],
177+
"tags": [{"line": 17, "name": "scenario-outline-passing-tag"}],
175178
"steps": [
176179
{
177-
"line": 16,
180+
"line": 19,
178181
"match": {"location": ""},
179182
"result": {"status": "passed", "duration": OfType(int)},
180183
"keyword": "Given",
181184
"name": "type str and value hello",
182185
}
183186
],
184-
"line": 15,
187+
"line": 18,
185188
"type": "scenario",
186189
"id": "test_passing_outline[str-hello]",
187190
"name": "Passing outline",
188191
},
189192
{
190193
"description": "",
191194
"keyword": "Scenario Outline",
192-
"tags": [{"line": 14, "name": "scenario-outline-passing-tag"}],
195+
"tags": [{"line": 17, "name": "scenario-outline-passing-tag"}],
193196
"steps": [
194197
{
195-
"line": 16,
198+
"line": 19,
196199
"match": {"location": ""},
197200
"result": {"status": "passed", "duration": OfType(int)},
198201
"keyword": "Given",
199202
"name": "type int and value 42",
200203
}
201204
],
202-
"line": 15,
205+
"line": 18,
203206
"type": "scenario",
204207
"id": "test_passing_outline[int-42]",
205208
"name": "Passing outline",
206209
},
207210
{
208211
"description": "",
209212
"keyword": "Scenario Outline",
210-
"tags": [{"line": 14, "name": "scenario-outline-passing-tag"}],
213+
"tags": [{"line": 17, "name": "scenario-outline-passing-tag"}],
211214
"steps": [
212215
{
213-
"line": 16,
216+
"line": 19,
214217
"match": {"location": ""},
215218
"result": {"status": "passed", "duration": OfType(int)},
216219
"keyword": "Given",
217220
"name": "type float and value 1.0",
218221
}
219222
],
220-
"line": 15,
223+
"line": 18,
221224
"type": "scenario",
222225
"id": "test_passing_outline[float-1.0]",
223226
"name": "Passing outline",

tests/feature/test_report.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def _(cucumbers, left):
117117
"keyword": "Scenario",
118118
"line_number": 5,
119119
"name": "Passing",
120+
"description": "",
120121
"steps": [
121122
{
122123
"duration": OfType(float),
@@ -155,6 +156,7 @@ def _(cucumbers, left):
155156
"keyword": "Scenario",
156157
"line_number": 10,
157158
"name": "Failing",
159+
"description": "",
158160
"steps": [
159161
{
160162
"duration": OfType(float),
@@ -192,6 +194,7 @@ def _(cucumbers, left):
192194
"keyword": "Scenario Outline",
193195
"line_number": 14,
194196
"name": "Outlined",
197+
"description": "",
195198
"steps": [
196199
{
197200
"duration": OfType(float),
@@ -237,6 +240,7 @@ def _(cucumbers, left):
237240
"keyword": "Scenario Outline",
238241
"line_number": 14,
239242
"name": "Outlined",
243+
"description": "",
240244
"steps": [
241245
{
242246
"duration": OfType(float),

0 commit comments

Comments
 (0)