From f42a6f6c6ad406e6c7245d3be41ebdaa62057d0d Mon Sep 17 00:00:00 2001 From: dgusakov Date: Wed, 20 Jan 2021 14:46:13 +0300 Subject: [PATCH 1/6] Fix missing fixtures in report when using lazy_fixture --- allure-pytest/src/listener.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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]) From fbd07f5a75e783676b0f6e4b4e0a7f620670bfed Mon Sep 17 00:00:00 2001 From: dgusakov Date: Mon, 25 Jan 2021 15:42:49 +0300 Subject: [PATCH 2/6] Add tests for lazy_fixture integration --- .../pytest_lazy_fixture/__init__.py | 0 .../pytest_lazy_fixture_test.py | 60 +++++++++++++++++++ allure-pytest/tox.ini | 1 + 3 files changed, 61 insertions(+) create mode 100644 allure-pytest/test/integration/pytest_lazy_fixture/__init__.py create mode 100644 allure-pytest/test/integration/pytest_lazy_fixture/pytest_lazy_fixture_test.py 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..4fcaf5fe --- /dev/null +++ b/allure-pytest/test/integration/pytest_lazy_fixture/pytest_lazy_fixture_test.py @@ -0,0 +1,60 @@ +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, has_after + + +@allure.feature("Integration") +def test_lazy_fixture(executed_docstring_source): + """ + >>> import pytest + ... from pytest_lazyfixture import lazy_fixture + + >>> @pytest.fixture + ... def my_lazy_fixture(): + ... yield + + >>> @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"), + has_after("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(): + ... yield + + >>> @pytest.fixture(params=lazy_fixture('my_lazy_fixture')) + ... def my_ordinary_fixture(): + ... yield + + >>> 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"), + has_after("my_lazy_fixture"), + has_before("my_ordinary_fixture"), + has_after("my_ordinary_fixture") + ), + ) + ) \ No newline at end of file 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 From 4687412c4dbe336c8009a7ca831d46465fbea68f Mon Sep 17 00:00:00 2001 From: dgusakov Date: Mon, 25 Jan 2021 15:44:50 +0300 Subject: [PATCH 3/6] Fix newline --- .../integration/pytest_lazy_fixture/pytest_lazy_fixture_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 4fcaf5fe..afc47d1a 100644 --- 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 @@ -57,4 +57,4 @@ def test_nested_lazy_fixture(executed_docstring_source): has_after("my_ordinary_fixture") ), ) - ) \ No newline at end of file + ) From c8d6d3a5cec12834472e19de843cd7d1bfc314f9 Mon Sep 17 00:00:00 2001 From: dgusakov Date: Mon, 25 Jan 2021 16:55:24 +0300 Subject: [PATCH 4/6] Fix tests --- .../pytest_lazy_fixture_test.py | 18 +++++++----------- allure-pytest/tox.ini | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) 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 index afc47d1a..970cf390 100644 --- 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 @@ -13,9 +13,9 @@ def test_lazy_fixture(executed_docstring_source): >>> @pytest.fixture ... def my_lazy_fixture(): - ... yield + ... pass - >>> @pytest.mark.parametrize('param', lazy_fixture('my_lazy_fixture')) + >>> @pytest.mark.parametrize('param', [lazy_fixture('my_lazy_fixture')]) ... def test_lazy_fixture_example(param): ... pass """ @@ -23,8 +23,7 @@ def test_lazy_fixture(executed_docstring_source): 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"), - has_after("my_lazy_fixture") + has_before("my_lazy_fixture") ), ) ) @@ -38,11 +37,11 @@ def test_nested_lazy_fixture(executed_docstring_source): >>> @pytest.fixture ... def my_lazy_fixture(): - ... yield + ... pass - >>> @pytest.fixture(params=lazy_fixture('my_lazy_fixture')) + >>> @pytest.fixture(params=[lazy_fixture('my_lazy_fixture')]) ... def my_ordinary_fixture(): - ... yield + ... pass >>> def test_nested_lazy_fixture_example(my_ordinary_fixture): ... pass @@ -51,10 +50,7 @@ def test_nested_lazy_fixture(executed_docstring_source): 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"), - has_after("my_lazy_fixture"), - has_before("my_ordinary_fixture"), - has_after("my_ordinary_fixture") + has_before("my_lazy_fixture") ), ) ) diff --git a/allure-pytest/tox.ini b/allure-pytest/tox.ini index ddbe325a..80fb7272 100644 --- a/allure-pytest/tox.ini +++ b/allure-pytest/tox.ini @@ -28,7 +28,7 @@ description = Test integration with pytest-flakes passenv = HOME -basepython = python3.6 +basepython = python3.7 setenv = ALLURE_INDENT_OUTPUT=yep @@ -46,7 +46,7 @@ commands = py.test --basetemp={envtmpdir}/tmp \ --alluredir={envtmpdir}/allure-results \ -W ignore::pytest.PytestExperimentalApiWarning \ - -p pytester {posargs: ./test/integration} + -p pytester {posargs: ./test/integration/pytest_lazy_fixture} [testenv:xdist] From 9ac84cb46cc0ae571388a79738be65c38e0196a9 Mon Sep 17 00:00:00 2001 From: dgusakov Date: Mon, 25 Jan 2021 16:58:05 +0300 Subject: [PATCH 5/6] Revert develop changes --- allure-pytest/tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/allure-pytest/tox.ini b/allure-pytest/tox.ini index 80fb7272..ddbe325a 100644 --- a/allure-pytest/tox.ini +++ b/allure-pytest/tox.ini @@ -28,7 +28,7 @@ description = Test integration with pytest-flakes passenv = HOME -basepython = python3.7 +basepython = python3.6 setenv = ALLURE_INDENT_OUTPUT=yep @@ -46,7 +46,7 @@ commands = py.test --basetemp={envtmpdir}/tmp \ --alluredir={envtmpdir}/allure-results \ -W ignore::pytest.PytestExperimentalApiWarning \ - -p pytester {posargs: ./test/integration/pytest_lazy_fixture} + -p pytester {posargs: ./test/integration} [testenv:xdist] From b324e96cb4dc29b184de45efb094971b71b316de Mon Sep 17 00:00:00 2001 From: dgusakov Date: Mon, 25 Jan 2021 17:00:47 +0300 Subject: [PATCH 6/6] Fix unused import --- .../integration/pytest_lazy_fixture/pytest_lazy_fixture_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 970cf390..809107a2 100644 --- 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 @@ -2,7 +2,7 @@ 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, has_after +from allure_commons_test.container import has_before @allure.feature("Integration")