forked from allure-framework/allure-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for bug fix allure-framework#474
- Loading branch information
Showing
2 changed files
with
58 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,46 @@ | ||
Feature: Feature Test | ||
Scenario: My Scenario Test | ||
Given two numbers: 2, 3 | ||
When addition it | ||
Then must be sum of it | ||
Feature: Bug #474 | ||
Scenario: allure.attach calling in method decorated with When and Pytest.fixture | ||
Given example.feature with content: | ||
""" | ||
Feature: Feature Test | ||
Scenario: My Scenario Test | ||
Given two numbers: 2, 3 | ||
When addition it | ||
Then must be sum of it | ||
""" | ||
And example_test.py with content: | ||
""" | ||
from pytest_bdd import scenario, given, when, then, parsers | ||
import pytest | ||
import allure | ||
a = 0 | ||
b = 0 | ||
@given(parsers.parse("two numbers: {first}, {second}")) | ||
def step_impl(first, second): | ||
global a, b | ||
a = first | ||
b = second | ||
@pytest.fixture() | ||
@when("addition it") | ||
def addition(): | ||
allure.attach('A text attachment in module scope fixture', 'blah blah blah', allure.attachment_type.TEXT) | ||
sum_ = a+b | ||
return sum_ | ||
@then("must be sum of it") | ||
def check_sum(addition): | ||
assert a+b == addition | ||
@scenario("example.feature", "My Scenario Test") | ||
def test_my_scenario(): | ||
pass | ||
""" | ||
When run pytest-bdd with allure | ||
Then attachment must be only in when-step attachments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,17 @@ | ||
from pytest_bdd import scenario, given, when, then, parsers | ||
import pytest | ||
import allure | ||
from pytest_bdd import scenario, then | ||
|
||
a = 0 | ||
b = 0 | ||
|
||
|
||
@given(parsers.parse("two numbers: {first}, {second}")) | ||
def step_impl(first, second): | ||
global a, b | ||
a = first | ||
b = second | ||
|
||
|
||
@pytest.fixture() | ||
@when("addition it") | ||
def addition(): | ||
allure.attach('A text attachment in module scope fixture', 'blah blah blah', allure.attachment_type.TEXT) | ||
sum_ = a+b | ||
return sum_ | ||
|
||
@scenario("bug474.feature", "allure.attach calling in method decorated with When and Pytest.fixture") | ||
def test_my_scenario(): | ||
pass | ||
|
||
@then("must be sum of it") | ||
def check_sum(addition): | ||
assert a+b == addition | ||
|
||
@then("attachment must be only in when-step attachments") | ||
def attachment_only_in_when(allure_report): | ||
test_case_report = allure_report.test_cases[0] | ||
when_step_report = next(step for step in test_case_report["steps"] | ||
if step["name"].startswith("When")) | ||
|
||
@scenario("bug474.feature", "My Scenario Test") | ||
def test_my_scenario(): | ||
pass | ||
assert "attachments" not in test_case_report.keys() | ||
assert len(when_step_report["attachments"]) == 1 | ||
assert when_step_report["attachments"][0]["name"] == "blah blah blah" |