Skip to content

Commit

Permalink
Add test for bug fix allure-framework#474
Browse files Browse the repository at this point in the history
  • Loading branch information
Duisus committed Jan 9, 2021
1 parent dce0f92 commit 5979b60
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 31 deletions.
51 changes: 46 additions & 5 deletions allure-pytest-bdd/test/Bug474Tests/bug474.feature
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
38 changes: 12 additions & 26 deletions allure-pytest-bdd/test/Bug474Tests/test_bug474.py
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"

0 comments on commit 5979b60

Please sign in to comment.