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
This commit is contained in:
Alessio Bogon 2024-12-02 22:17:32 +01:00 committed by GitHub
commit 6a2b2fbfbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 20 deletions

View File

@ -15,6 +15,7 @@ Added
Changed
+++++++
* Step arguments ``"datatable"`` and ``"docstring"`` are now reserved, and they can't be used as step argument names.
* Scenario ``description`` field is now set for JSON output
Deprecated
++++++++++

View File

@ -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"]],

View File

@ -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,

View File

@ -51,9 +51,12 @@ def test_step_trace(pytester):
"""
@feature-tag
Feature: One passing scenario, one failing scenario
This is a feature description
@scenario-passing-tag
Scenario: Passing
This is a scenario description
Given a passing step
And some other passing step
@ -116,72 +119,72 @@ def test_step_trace(pytester):
assert result.ret
expected = [
{
"description": "",
"description": "This is a feature description",
"elements": [
{
"description": "",
"description": "This is a scenario description",
"id": "test_passing",
"keyword": "Scenario",
"line": 5,
"line": 6,
"name": "Passing",
"steps": [
{
"keyword": "Given",
"line": 6,
"line": 9,
"match": {"location": ""},
"name": "a passing step",
"result": {"status": "passed", "duration": OfType(int)},
},
{
"keyword": "And",
"line": 7,
"line": 10,
"match": {"location": ""},
"name": "some other passing step",
"result": {"status": "passed", "duration": OfType(int)},
},
],
"tags": [{"name": "scenario-passing-tag", "line": 4}],
"tags": [{"name": "scenario-passing-tag", "line": 5}],
"type": "scenario",
},
{
"description": "",
"id": "test_failing",
"keyword": "Scenario",
"line": 10,
"line": 13,
"name": "Failing",
"steps": [
{
"keyword": "Given",
"line": 11,
"line": 14,
"match": {"location": ""},
"name": "a passing step",
"result": {"status": "passed", "duration": OfType(int)},
},
{
"keyword": "And",
"line": 12,
"line": 15,
"match": {"location": ""},
"name": "a failing step",
"result": {"error_message": OfType(str), "status": "failed", "duration": OfType(int)},
},
],
"tags": [{"name": "scenario-failing-tag", "line": 9}],
"tags": [{"name": "scenario-failing-tag", "line": 12}],
"type": "scenario",
},
{
"description": "",
"keyword": "Scenario Outline",
"tags": [{"line": 14, "name": "scenario-outline-passing-tag"}],
"tags": [{"line": 17, "name": "scenario-outline-passing-tag"}],
"steps": [
{
"line": 16,
"line": 19,
"match": {"location": ""},
"result": {"status": "passed", "duration": OfType(int)},
"keyword": "Given",
"name": "type str and value hello",
}
],
"line": 15,
"line": 18,
"type": "scenario",
"id": "test_passing_outline[str-hello]",
"name": "Passing outline",
@ -189,17 +192,17 @@ def test_step_trace(pytester):
{
"description": "",
"keyword": "Scenario Outline",
"tags": [{"line": 14, "name": "scenario-outline-passing-tag"}],
"tags": [{"line": 17, "name": "scenario-outline-passing-tag"}],
"steps": [
{
"line": 16,
"line": 19,
"match": {"location": ""},
"result": {"status": "passed", "duration": OfType(int)},
"keyword": "Given",
"name": "type int and value 42",
}
],
"line": 15,
"line": 18,
"type": "scenario",
"id": "test_passing_outline[int-42]",
"name": "Passing outline",
@ -207,17 +210,17 @@ def test_step_trace(pytester):
{
"description": "",
"keyword": "Scenario Outline",
"tags": [{"line": 14, "name": "scenario-outline-passing-tag"}],
"tags": [{"line": 17, "name": "scenario-outline-passing-tag"}],
"steps": [
{
"line": 16,
"line": 19,
"match": {"location": ""},
"result": {"status": "passed", "duration": OfType(int)},
"keyword": "Given",
"name": "type float and value 1.0",
}
],
"line": 15,
"line": 18,
"type": "scenario",
"id": "test_passing_outline[float-1.0]",
"name": "Passing outline",

View File

@ -117,6 +117,7 @@ def test_step_trace(pytester):
"keyword": "Scenario",
"line_number": 5,
"name": "Passing",
"description": "",
"steps": [
{
"duration": OfType(float),
@ -155,6 +156,7 @@ def test_step_trace(pytester):
"keyword": "Scenario",
"line_number": 10,
"name": "Failing",
"description": "",
"steps": [
{
"duration": OfType(float),
@ -192,6 +194,7 @@ def test_step_trace(pytester):
"keyword": "Scenario Outline",
"line_number": 14,
"name": "Outlined",
"description": "",
"steps": [
{
"duration": OfType(float),
@ -237,6 +240,7 @@ def test_step_trace(pytester):
"keyword": "Scenario Outline",
"line_number": 14,
"name": "Outlined",
"description": "",
"steps": [
{
"duration": OfType(float),