From f43e42b2dea65fa147c0dff25c13c1a8e9acfeb3 Mon Sep 17 00:00:00 2001 From: skhomuti Date: Tue, 11 Oct 2022 19:35:35 +0400 Subject: [PATCH] No need to update fixtures in test teardown because all fixtures are already finished at this moment and no way to run they again --- allure-pytest/src/listener.py | 1 - .../test/acceptance/fixture/fixture_test.py | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/allure-pytest/src/listener.py b/allure-pytest/src/listener.py index 131f36d0..d56751b5 100644 --- a/allure-pytest/src/listener.py +++ b/allure-pytest/src/listener.py @@ -115,7 +115,6 @@ def pytest_runtest_call(self, item): @pytest.hookimpl(hookwrapper=True) def pytest_runtest_teardown(self, item): yield - self._update_fixtures_children(item) uuid = self._cache.get(item.nodeid) test_result = self.allure_logger.get_test(uuid) test_result.labels.extend([Label(name=name, value=value) for name, value in allure_labels(item)]) diff --git a/allure-pytest/test/acceptance/fixture/fixture_test.py b/allure-pytest/test/acceptance/fixture/fixture_test.py index 7e1260a6..35aa10fd 100644 --- a/allure-pytest/test/acceptance/fixture/fixture_test.py +++ b/allure-pytest/test/acceptance/fixture/fixture_test.py @@ -372,3 +372,42 @@ def test_three(request): ) ) ) + + +def test_one_fixture_on_two_tests(allured_testdir): + allured_testdir.testdir.makepyfile(""" + import pytest + import allure + + @pytest.fixture + def fixture(request): + with allure.step(request.node.name): + pass + + class TestClass: + def test_first(self, fixture): + pass + + def test_second(self, fixture): + pass + """) + allured_testdir.run_with_allure() + + assert_that(allured_testdir.allure_report, + has_test_case("test_first", + has_container(allured_testdir.allure_report, + has_before("fixture", has_step("test_first")), + ), + not_(has_container(allured_testdir.allure_report, + has_before("fixture", has_step("test_second")), + )) + ), + has_test_case("test_second", + has_container(allured_testdir.allure_report, + has_before("fixture", has_step("test_second")), + ), + not_(has_container(allured_testdir.allure_report, + has_before("fixture", has_step("test_first")), + )) + ) + )