From e19288ac07da40730838275da4b091c1eaef31a7 Mon Sep 17 00:00:00 2001 From: Jason Allen Date: Sun, 1 Dec 2024 19:43:47 +0000 Subject: [PATCH] Add missing scenario description in json --- src/pytest_bdd/cucumber_json.py | 2 +- src/pytest_bdd/reporting.py | 1 + tests/feature/test_cucumber_json.py | 34 +++++++++++++++-------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/pytest_bdd/cucumber_json.py b/src/pytest_bdd/cucumber_json.py index 31dabb7..c9bd975 100644 --- a/src/pytest_bdd/cucumber_json.py +++ b/src/pytest_bdd/cucumber_json.py @@ -131,7 +131,7 @@ class LogBDDCucumberJSON: "id": report.item["name"], "name": scenario["name"], "line": scenario["line_number"], - "description": "", + "description": scenario["description"], "tags": self._serialize_tags(scenario), "type": "scenario", "steps": [stepmap(step) for step in scenario["steps"]], diff --git a/src/pytest_bdd/reporting.py b/src/pytest_bdd/reporting.py index 48d7263..e92cc3e 100644 --- a/src/pytest_bdd/reporting.py +++ b/src/pytest_bdd/reporting.py @@ -113,6 +113,7 @@ class ScenarioReport: "name": scenario.name, "line_number": scenario.line_number, "tags": sorted(scenario.tags), + "description": scenario.description, "feature": { "keyword": feature.keyword, "name": feature.name, diff --git a/tests/feature/test_cucumber_json.py b/tests/feature/test_cucumber_json.py index dd8602a..6e6239c 100644 --- a/tests/feature/test_cucumber_json.py +++ b/tests/feature/test_cucumber_json.py @@ -55,6 +55,8 @@ def test_step_trace(pytester): @scenario-passing-tag Scenario: Passing + This is a scenario description + Given a passing step And some other passing step @@ -120,7 +122,7 @@ def test_step_trace(pytester): "description": "This is a feature description", "elements": [ { - "description": "", + "description": "This is a scenario description", "id": "test_passing", "keyword": "Scenario", "line": 6, @@ -128,14 +130,14 @@ def test_step_trace(pytester): "steps": [ { "keyword": "Given", - "line": 7, + "line": 9, "match": {"location": ""}, "name": "a passing step", "result": {"status": "passed", "duration": OfType(int)}, }, { "keyword": "And", - "line": 8, + "line": 10, "match": {"location": ""}, "name": "some other passing step", "result": {"status": "passed", "duration": OfType(int)}, @@ -148,41 +150,41 @@ def test_step_trace(pytester): "description": "", "id": "test_failing", "keyword": "Scenario", - "line": 11, + "line": 13, "name": "Failing", "steps": [ { "keyword": "Given", - "line": 12, + "line": 14, "match": {"location": ""}, "name": "a passing step", "result": {"status": "passed", "duration": OfType(int)}, }, { "keyword": "And", - "line": 13, + "line": 15, "match": {"location": ""}, "name": "a failing step", "result": {"error_message": OfType(str), "status": "failed", "duration": OfType(int)}, }, ], - "tags": [{"name": "scenario-failing-tag", "line": 10}], + "tags": [{"name": "scenario-failing-tag", "line": 12}], "type": "scenario", }, { "description": "", "keyword": "Scenario Outline", - "tags": [{"line": 15, "name": "scenario-outline-passing-tag"}], + "tags": [{"line": 17, "name": "scenario-outline-passing-tag"}], "steps": [ { - "line": 17, + "line": 19, "match": {"location": ""}, "result": {"status": "passed", "duration": OfType(int)}, "keyword": "Given", "name": "type str and value hello", } ], - "line": 16, + "line": 18, "type": "scenario", "id": "test_passing_outline[str-hello]", "name": "Passing outline", @@ -190,17 +192,17 @@ def test_step_trace(pytester): { "description": "", "keyword": "Scenario Outline", - "tags": [{"line": 15, "name": "scenario-outline-passing-tag"}], + "tags": [{"line": 17, "name": "scenario-outline-passing-tag"}], "steps": [ { - "line": 17, + "line": 19, "match": {"location": ""}, "result": {"status": "passed", "duration": OfType(int)}, "keyword": "Given", "name": "type int and value 42", } ], - "line": 16, + "line": 18, "type": "scenario", "id": "test_passing_outline[int-42]", "name": "Passing outline", @@ -208,17 +210,17 @@ def test_step_trace(pytester): { "description": "", "keyword": "Scenario Outline", - "tags": [{"line": 15, "name": "scenario-outline-passing-tag"}], + "tags": [{"line": 17, "name": "scenario-outline-passing-tag"}], "steps": [ { - "line": 17, + "line": 19, "match": {"location": ""}, "result": {"status": "passed", "duration": OfType(int)}, "keyword": "Given", "name": "type float and value 1.0", } ], - "line": 16, + "line": 18, "type": "scenario", "id": "test_passing_outline[float-1.0]", "name": "Passing outline",