Skip to content

Commit

Permalink
Fix missing fixtures in report when using lazy_fixture (via #548)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgusakov authored Jan 25, 2021
1 parent 163f08c commit 6e7fe49
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ def _test_fixtures(item):
fixturemanager = item.session._fixturemanager
fixturedefs = []

if hasattr(item, "fixturenames"):
for name in item.fixturenames:
if hasattr(item._request, "fixturenames"):
for name in item._request.fixturenames:
fixturedef = fixturemanager.getfixturedefs(name, item.nodeid)
if fixturedef:
fixturedefs.append(fixturedef[-1])
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import allure
from hamcrest import assert_that
from allure_commons_test.report import has_test_case
from allure_commons_test.container import has_container
from allure_commons_test.container import has_before


@allure.feature("Integration")
def test_lazy_fixture(executed_docstring_source):
"""
>>> import pytest
... from pytest_lazyfixture import lazy_fixture
>>> @pytest.fixture
... def my_lazy_fixture():
... pass
>>> @pytest.mark.parametrize('param', [lazy_fixture('my_lazy_fixture')])
... def test_lazy_fixture_example(param):
... pass
"""

assert_that(executed_docstring_source.allure_report,
has_test_case("test_lazy_fixture_example",
has_container(executed_docstring_source.allure_report,
has_before("my_lazy_fixture")
),
)
)


@allure.feature("Integration")
def test_nested_lazy_fixture(executed_docstring_source):
"""
>>> import pytest
... from pytest_lazyfixture import lazy_fixture
>>> @pytest.fixture
... def my_lazy_fixture():
... pass
>>> @pytest.fixture(params=[lazy_fixture('my_lazy_fixture')])
... def my_ordinary_fixture():
... pass
>>> def test_nested_lazy_fixture_example(my_ordinary_fixture):
... pass
"""

assert_that(executed_docstring_source.allure_report,
has_test_case("test_nested_lazy_fixture_example",
has_container(executed_docstring_source.allure_report,
has_before("my_lazy_fixture")
),
)
)
1 change: 1 addition & 0 deletions allure-pytest/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ deps =
pytest-flakes
pytest-rerunfailures
pytest-xdist
pytest-lazy-fixture
mock
{distshare}/allure-python-commons-2*.zip
{distshare}/allure-python-commons-test-2*.zip
Expand Down

0 comments on commit 6e7fe49

Please sign in to comment.