diff --git a/allure-pytest/src/listener.py b/allure-pytest/src/listener.py index 879616b9..b7da35c8 100644 --- a/allure-pytest/src/listener.py +++ b/allure-pytest/src/listener.py @@ -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]) diff --git a/allure-pytest/test/integration/pytest_lazy_fixture/__init__.py b/allure-pytest/test/integration/pytest_lazy_fixture/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/allure-pytest/test/integration/pytest_lazy_fixture/pytest_lazy_fixture_test.py b/allure-pytest/test/integration/pytest_lazy_fixture/pytest_lazy_fixture_test.py new file mode 100644 index 00000000..809107a2 --- /dev/null +++ b/allure-pytest/test/integration/pytest_lazy_fixture/pytest_lazy_fixture_test.py @@ -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") + ), + ) + ) diff --git a/allure-pytest/tox.ini b/allure-pytest/tox.ini index ac292701..ddbe325a 100644 --- a/allure-pytest/tox.ini +++ b/allure-pytest/tox.ini @@ -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