Skip to content

Commit a4e7f7f

Browse files
author
Dmitry Gusakov
authored
fix redefined fixtures handling (via #592)
1 parent b2e64d4 commit a4e7f7f

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

allure-pytest/src/listener.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ def __init__(self):
268268
self._items = dict()
269269

270270
def get(self, _id):
271-
return self._items.get(str(_id))
271+
return self._items.get(id(_id))
272272

273273
def push(self, _id):
274-
return self._items.setdefault(str(_id), uuid4())
274+
return self._items.setdefault(id(_id), uuid4())
275275

276276
def pop(self, _id):
277-
return self._items.pop(str(_id), None)
277+
return self._items.pop(id(_id), None)
278278

279279

280280
def _test_fixtures(item):
@@ -283,8 +283,8 @@ def _test_fixtures(item):
283283

284284
if hasattr(item, "_request") and hasattr(item._request, "fixturenames"):
285285
for name in item._request.fixturenames:
286-
fixturedef = fixturemanager.getfixturedefs(name, item.nodeid)
287-
if fixturedef:
288-
fixturedefs.append(fixturedef[-1])
286+
fixturedefs_pytest = fixturemanager.getfixturedefs(name, item.nodeid)
287+
if fixturedefs_pytest:
288+
fixturedefs.extend(fixturedefs_pytest)
289289

290290
return fixturedefs

allure-pytest/test/acceptance/fixture/fixture_test.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import allure
33
from hamcrest import assert_that, not_
44
from allure_commons_test.report import has_test_case
5-
from allure_commons_test.container import has_container
6-
from allure_commons_test.container import has_before
5+
from allure_commons_test.container import has_container, has_before, has_after
6+
from allure_commons_test.result import has_step
77
from itertools import combinations_with_replacement
88

99
fixture_scopes = ["session", "module", "class", "function"]
@@ -217,3 +217,58 @@ def test_with_titled_conftest_fixtures(first_fixture, second_fixture):
217217
)
218218
)
219219
)
220+
221+
222+
def test_fixture_override(allured_testdir):
223+
allured_testdir.testdir.makeconftest("""
224+
import pytest
225+
import allure
226+
227+
@pytest.fixture
228+
def my_fixture():
229+
with allure.step('Step in before in original fixture'):
230+
pass
231+
yield
232+
with allure.step('Step in after in original fixture'):
233+
pass
234+
235+
""")
236+
237+
allured_testdir.testdir.makepyfile("""
238+
import pytest
239+
import allure
240+
241+
@pytest.fixture
242+
def my_fixture(my_fixture):
243+
with allure.step('Step in before in redefined fixture'):
244+
pass
245+
yield
246+
with allure.step('Step in after in redefined fixture'):
247+
pass
248+
249+
def test_with_redefined_fixture(my_fixture):
250+
pass
251+
""")
252+
253+
allured_testdir.run_with_allure()
254+
255+
assert_that(allured_testdir.allure_report,
256+
has_test_case("test_with_redefined_fixture",
257+
has_container(allured_testdir.allure_report,
258+
has_before("my_fixture",
259+
has_step("Step in before in original fixture")
260+
),
261+
has_after("my_fixture::0",
262+
has_step("Step in after in original fixture")
263+
)
264+
),
265+
has_container(allured_testdir.allure_report,
266+
has_before("my_fixture",
267+
has_step("Step in before in redefined fixture")
268+
),
269+
has_after("my_fixture::0",
270+
has_step("Step in after in redefined fixture")
271+
)
272+
),
273+
)
274+
)

0 commit comments

Comments
 (0)