Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 234 add scenario attach method #329

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pytest_bdd/cucumber_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def stepmap(step):
"keyword": step["keyword"],
"name": step_name,
"line": step["line_number"],
"embeddings": step["embeddings"],
"match": {"location": ""},
"result": self._get_result(step, report, error_message),
}
Expand Down
18 changes: 18 additions & 0 deletions pytest_bdd/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,14 @@ def add_step(self, step):
step.scenario = self
self._steps.append(step)

def attach(self, data, media_type="text/plain"):
"""Add attachment to step, such as text, images.

:param data: actual data of Attachment, can be plain text or base64 encoded
:param media_type: actual media type of Attachment, such as text/plain, image/png
"""
self.steps[-1].attach(data, media_type)

@property
def steps(self):
"""Get scenario steps including background steps.
Expand Down Expand Up @@ -521,6 +529,7 @@ def __init__(self, name, type, indent, line_number, keyword):
self.type = type
self.line_number = line_number
self.failed = False
self.embeddings = []
self.start = 0
self.stop = 0
self.scenario = None
Expand All @@ -533,6 +542,15 @@ def add_line(self, line):
"""
self.lines.append(line)

def attach(self, data, media_type="text/plain"):
"""Add attachment to step, such as text, images.

:param data: actual data of Attachment, can be plain text or base64 encoded
:param media_type: actual media type of Attachment, such as text/plain, image/png
"""
json_attachment = {"data": data, "media": {"type": media_type}}
self.embeddings.append(json_attachment)

@property
def name(self):
"""Get step name."""
Expand Down
1 change: 1 addition & 0 deletions pytest_bdd/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def serialize(self):
"""
return {
"name": self.step.name,
"embeddings": self.step.embeddings,
"type": self.step.type,
"keyword": self.step.keyword,
"line_number": self.step.line_number,
Expand Down
7 changes: 7 additions & 0 deletions tests/feature/test_cucumber_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ def test_passing_outline():
"steps": [
{
"keyword": "Given",
"embeddings": [],
"line": 6,
"match": {"location": ""},
"name": "a passing step",
"result": {"status": "passed", "duration": equals_any(int)},
},
{
"keyword": "And",
"embeddings": [],
"line": 7,
"match": {"location": ""},
"name": "some other passing step",
Expand All @@ -149,13 +151,15 @@ def test_passing_outline():
"steps": [
{
"keyword": "Given",
"embeddings": [],
"line": 11,
"match": {"location": ""},
"name": "a passing step",
"result": {"status": "passed", "duration": equals_any(int)},
},
{
"keyword": "And",
"embeddings": [],
"line": 12,
"match": {"location": ""},
"name": "a failing step",
Expand All @@ -176,6 +180,7 @@ def test_passing_outline():
"steps": [
{
"line": 16,
"embeddings": [],
"match": {"location": ""},
"result": {"status": "passed", "duration": equals_any(int)},
"keyword": "Given",
Expand All @@ -194,6 +199,7 @@ def test_passing_outline():
"steps": [
{
"line": 16,
"embeddings": [],
"match": {"location": ""},
"result": {"status": "passed", "duration": equals_any(int)},
"keyword": "Given",
Expand All @@ -212,6 +218,7 @@ def test_passing_outline():
"steps": [
{
"line": 16,
"embeddings": [],
"match": {"location": ""},
"result": {"status": "passed", "duration": equals_any(int)},
"keyword": "Given",
Expand Down
10 changes: 10 additions & 0 deletions tests/feature/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
"steps": [
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "Given",
"line_number": 6,
Expand All @@ -130,6 +131,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
},
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "And",
"line_number": 7,
Expand Down Expand Up @@ -159,6 +161,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
"steps": [
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "Given",
"line_number": 11,
Expand All @@ -167,6 +170,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
},
{
"duration": equals_any(float),
"embeddings": [],
"failed": True,
"keyword": "And",
"line_number": 12,
Expand Down Expand Up @@ -195,6 +199,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
"steps": [
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "Given",
"line_number": 15,
Expand All @@ -203,6 +208,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
},
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "When",
"line_number": 16,
Expand All @@ -211,6 +217,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
},
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "Then",
"line_number": 17,
Expand Down Expand Up @@ -246,6 +253,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
"steps": [
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "Given",
"line_number": 15,
Expand All @@ -254,6 +262,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
},
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "When",
"line_number": 16,
Expand All @@ -262,6 +271,7 @@ def should_have_left_cucumbers(start_cucumbers, start, eat, left):
},
{
"duration": equals_any(float),
"embeddings": [],
"failed": False,
"keyword": "Then",
"line_number": 17,
Expand Down