def test_fixture(allured_testdir, first_scope, second_scope): allured_testdir.testdir.makepyfile(""" import pytest @pytest.fixture(scope="{first_scope}") def first_fixture(): pass @pytest.fixture(scope="{second_scope}") def second_fixture(): pass def test_fixture_example(first_fixture, second_fixture): pass """.format(first_scope=first_scope, second_scope=second_scope)) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_fixture_example", has_container(allured_testdir.allure_report, has_before("first_fixture")), has_container( allured_testdir.allure_report, has_before("second_fixture"), )))
def test_fixture(allured_testdir, first_scope, second_scope): allured_testdir.testdir.makepyfile(""" import pytest @pytest.fixture(scope="{first_scope}") def first_fixture(): pass @pytest.fixture(scope="{second_scope}") def second_fixture(): pass def test_fixture_example(first_fixture, second_fixture): pass """.format(first_scope=first_scope, second_scope=second_scope)) allured_testdir.run_with_allure() assert_that(allured_testdir.allure_report, has_test_case("test_fixture_example", has_container(allured_testdir.allure_report, has_before("first_fixture") ), has_container(allured_testdir.allure_report, has_before("second_fixture"), ) ) )
def test_titled_fixture_from_conftest(allured_testdir): allured_testdir.testdir.makeconftest(""" import allure import pytest @allure.title('Titled fixture before pytest.fixture') @pytest.fixture def first_fixture(): pass @pytest.fixture @allure.title('Titled fixture after pytest.fixture') def second_fixture(): pass """) allured_testdir.testdir.makepyfile(""" def test_with_titled_conftest_fixtures(first_fixture, second_fixture): pass """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_with_titled_conftest_fixtures", has_container(allured_testdir.allure_report, has_before("Titled fixture before pytest.fixture")), has_container(allured_testdir.allure_report, has_before("Titled fixture after pytest.fixture"))))
def test_group_with_test_setup(self): assert_that( self.allure_report, has_test_case( 'Case With Test Setup', has_container( self.allure_report, has_container( self.allure_report, all_of(has_before('Suite Setup Keyword'), has_after('Suite Teardown Keyword'))), has_before('Test Setup Keyword'))), )
def test_fixture_override(allured_testdir): allured_testdir.testdir.makeconftest(""" import pytest import allure @pytest.fixture def my_fixture(): with allure.step('Step in before in original fixture'): pass yield with allure.step('Step in after in original fixture'): pass """) allured_testdir.testdir.makepyfile(""" import pytest import allure @pytest.fixture def my_fixture(my_fixture): with allure.step('Step in before in redefined fixture'): pass yield with allure.step('Step in after in redefined fixture'): pass def test_with_redefined_fixture(my_fixture): pass """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_with_redefined_fixture", has_container( allured_testdir.allure_report, has_before("my_fixture", has_step("Step in before in original fixture")), has_after("my_fixture::0", has_step("Step in after in original fixture"))), has_container( allured_testdir.allure_report, has_before("my_fixture", has_step("Step in before in redefined fixture")), has_after("my_fixture::0", has_step("Step in after in redefined fixture"))), ))
def test_fixture_finalizer(executed_docstring_source): """ >>> import pytest Let"s define fixture with finalizer: >>> @pytest.fixture ... def fixture_with_finalizer(request): ... def finalizer(): ... pass ... request.addfinalizer(finalizer) For next test, allure will report fixture finalizer in TearDown section >>> def test_fixture_with_finalizer_example(fixture_with_finalizer): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_fixture_with_finalizer_example", has_container( executed_docstring_source.allure_report, has_before("fixture_with_finalizer"), has_after("{fixture}::{finalizer}".format( fixture="fixture_with_finalizer", finalizer="finalizer")))))
def test_fixture_finalizers(executed_docstring_source): """ >>> import pytest In pytest, you can define several finalizers for one fixture, like this: >>> @pytest.fixture ... def fixture_with_finalizers(request): ... def first_finalizer(): ... pass ... request.addfinalizer(first_finalizer) ... ... def second_finalizer(): ... pass ... request.addfinalizer(second_finalizer) Of course, allure will report all of them >>> def test_fixture_with_finalizers_example(fixture_with_finalizers): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_fixture_with_finalizers_example", has_container( executed_docstring_source.allure_report, has_before("fixture_with_finalizers"), has_after("{fixture}::{finalizer}".format( fixture="fixture_with_finalizers", finalizer="first_finalizer")), has_after( "{fixture}::{finalizer}".format( fixture="fixture_with_finalizers", finalizer="second_finalizer"), ))))
def test_fixture_with_step_from_conftest(allured_testdir): allured_testdir.testdir.makeconftest(""" import allure import pytest @allure.step("step in conftest.py") def conftest_step(): pass @pytest.fixture def fixture_with_conftest_step(): conftest_step() """) allured_testdir.testdir.makepyfile(""" def test_fixture_with_step_from_conftest_example(fixture_with_conftest_step): pass """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_fixture_with_step_from_conftest_example", has_container( allured_testdir.allure_report, has_before("fixture_with_conftest_step", has_step("step in conftest.py")))))
def test_fixture_finalizer(executed_docstring_source): """ >>> import pytest Let"s define fixture with finalizer: >>> @pytest.fixture ... def fixture_with_finalizer(request): ... def finalizer(): ... pass ... request.addfinalizer(finalizer) For next test, allure will report fixture finalizer in TearDown section >>> def test_fixture_with_finalizer_example(fixture_with_finalizer): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_fixture_with_finalizer_example", has_container(executed_docstring_source.allure_report, has_before("fixture_with_finalizer"), has_after("{fixture}::{finalizer}".format(fixture="fixture_with_finalizer", finalizer="finalizer") ) ) ) )
def test_fixture_finalizers(executed_docstring_source): """ >>> import pytest In pytest, you can define several finalizers for one fixture, like this: >>> @pytest.fixture ... def fixture_with_finalizers(request): ... def first_finalizer(): ... pass ... request.addfinalizer(first_finalizer) ... ... def second_finalizer(): ... pass ... request.addfinalizer(second_finalizer) Of course, allure will report all of them >>> def test_fixture_with_finalizers_example(fixture_with_finalizers): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_fixture_with_finalizers_example", has_container(executed_docstring_source.allure_report, has_before("fixture_with_finalizers"), has_after("{fixture}::{finalizer}".format(fixture="fixture_with_finalizers", finalizer="first_finalizer") ), has_after("{fixture}::{finalizer}".format(fixture="fixture_with_finalizers", finalizer="second_finalizer"), ) ) ) )
def test_xfail_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def broken_fixture(): ... raise NotImplementedError >>> @pytest.mark.xfail() ... def test_xfail_fixture_example(broken_fixture): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_xfail_fixture_example", with_status("skipped"), has_status_details(with_message_contains("NotImplementedError"), with_trace_contains("def broken_fixture():")), has_container( executed_docstring_source.allure_report, has_before( "broken_fixture", with_status("broken"), has_status_details( with_message_contains("NotImplementedError"), with_trace_contains("broken_fixture")), ), )))
def test_skip_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def skip_fixture(): ... pytest.skip() >>> @pytest.mark.xfail() ... def test_skip_fixture_example(skip_fixture): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_skip_fixture_example", with_status("skipped"), has_status_details( with_message_contains("Skipped: <Skipped instance>")), has_container( executed_docstring_source.allure_report, has_before( "skip_fixture", with_status("skipped"), has_status_details( with_message_contains("Skipped: <Skipped instance>"), with_trace_contains("skip_fixture")), ), )))
def test_fixture_with_step_from_conftest(allured_testdir): allured_testdir.testdir.makeconftest(""" import allure import pytest @allure.step("step in conftest.py") def conftest_step(): pass @pytest.fixture def fixture_with_conftest_step(): conftest_step() """) allured_testdir.testdir.makepyfile(""" def test_fixture_with_step_from_conftest_example(fixture_with_conftest_step): pass """) allured_testdir.run_with_allure() assert_that(allured_testdir.allure_report, has_test_case("test_fixture_with_step_from_conftest_example", has_container(allured_testdir.allure_report, has_before("fixture_with_conftest_step", has_step("step in conftest.py") ) ) ) )
def test_opened_step_function(executed_docstring_source): """ >>> import allure >>> import pytest >>> @pytest.fixture() ... def yield_fixture(): ... with allure.step("Opened step"): ... yield >>> def test_opened_step(yield_fixture): ... with allure.step("Body step"): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_opened_step", all_of( has_step("Body step"), has_container( executed_docstring_source.allure_report, has_before( "yield_fixture", has_step("Opened step", not_(has_step("Body step"))))), )))
def test_failed_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def failed_fixture(): ... assert False >>> def test_failed_fixture_example(failed_fixture): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_failed_fixture_example", with_status("failed"), has_status_details(with_message_contains("AssertionError"), with_trace_contains("def failed_fixture():") ), has_container(executed_docstring_source.allure_report, has_before("failed_fixture", with_status("failed"), has_status_details(with_message_contains("AssertionError"), with_trace_contains("failed_fixture") ), ), ) ) )
def test_failed_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def failed_fixture(): ... assert False >>> def test_failed_fixture_example(failed_fixture): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_failed_fixture_example", with_status("failed"), has_status_details(with_message_contains("AssertionError"), with_trace_contains("def failed_fixture():")), has_container( executed_docstring_source.allure_report, has_before( "failed_fixture", with_status("failed"), has_status_details(with_message_contains("AssertionError"), with_trace_contains("failed_fixture")), ), )))
def test_pytest_fail_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def pytest_fail_fixture(): ... pytest.fail() >>> def test_pytest_fail_fixture_example(pytest_fail_fixture): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_pytest_fail_fixture_example", with_status("failed"), has_status_details( with_message_contains("Failed: <Failed instance>"), with_trace_contains("def pytest_fail_fixture():")), has_container( executed_docstring_source.allure_report, has_before( "pytest_fail_fixture", with_status("failed"), has_status_details( with_message_contains("Failed: <Failed instance>"), with_trace_contains("pytest_fail_fixture")), ), )))
def test_pytest_fail_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def pytest_fail_fixture(): ... pytest.fail() >>> def test_pytest_fail_fixture_example(pytest_fail_fixture): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_pytest_fail_fixture_example", with_status("failed"), has_status_details(with_message_contains("Failed: <Failed instance>"), with_trace_contains("def pytest_fail_fixture():") ), has_container(executed_docstring_source.allure_report, has_before("pytest_fail_fixture", with_status("failed"), has_status_details( with_message_contains("Failed: <Failed instance>"), with_trace_contains("pytest_fail_fixture") ), ), ) ) )
def test_broken_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def broken_fixture(): ... raise IndexError >>> def test_broken_fixture_example(broken_fixture): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_broken_fixture_example", with_status("broken"), has_status_details(with_message_contains("IndexError"), with_trace_contains("def broken_fixture():") ), has_container(executed_docstring_source.allure_report, has_before("broken_fixture", with_status("broken"), has_status_details(with_message_contains("IndexError"), with_trace_contains("broken_fixture") ), ), ) ) )
def test_case_with_setup(self): assert_that( self.allure_report, has_test_case( 'Case With Test Setup', has_container(self.allure_report, has_before('Test Setup Keyword'))), )
def test_fixture_attachment(executed_docstring_path): assert_that( executed_docstring_path.allure_report, has_test_case( "test_fixture_attachment", has_container( executed_docstring_path.allure_report, has_before("fixture_with_attachment", has_attachment()))))
def test_nested_fixture(allured_testdir, parent_scope, child_scope): allured_testdir.testdir.makepyfile(""" import pytest @pytest.fixture(scope="{parent_scope}") def parent_fixture(): pass @pytest.fixture(scope="{child_scope}") def child_fixture(parent_fixture): pass def test_nested_fixture_example(child_fixture): pass def test_fixture_used_in_other_fixtures_example(parent_fixture): pass """.format(parent_scope=parent_scope, child_scope=child_scope)) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_nested_fixture_example", has_container(allured_testdir.allure_report, has_before("parent_fixture")), has_container( allured_testdir.allure_report, has_before("child_fixture"), ))) assert_that( allured_testdir.allure_report, has_test_case( "test_fixture_used_in_other_fixtures_example", has_container(allured_testdir.allure_report, has_before("parent_fixture")), not_( has_container( allured_testdir.allure_report, has_before("child_fixture"), ))))
def test_nested_fixture(allured_testdir, parent_scope, child_scope): allured_testdir.testdir.makepyfile(""" import pytest @pytest.fixture(scope="{parent_scope}") def parent_fixture(): pass @pytest.fixture(scope="{child_scope}") def child_fixture(parent_fixture): pass def test_nested_fixture_example(child_fixture): pass def test_fixture_used_in_other_fixtures_example(parent_fixture): pass """.format(parent_scope=parent_scope, child_scope=child_scope)) allured_testdir.run_with_allure() assert_that(allured_testdir.allure_report, has_test_case("test_nested_fixture_example", has_container(allured_testdir.allure_report, has_before("parent_fixture") ), has_container(allured_testdir.allure_report, has_before("child_fixture"), ) ) ) assert_that(allured_testdir.allure_report, has_test_case("test_fixture_used_in_other_fixtures_example", has_container(allured_testdir.allure_report, has_before("parent_fixture") ), not_(has_container(allured_testdir.allure_report, has_before("child_fixture"), ) ) ) )
def test_case_with_fixtures(self): assert_that( self.allure_report, has_test_case( 'Case With Test Fixtures', has_container( self.allure_report, all_of(has_before('Test Setup Keyword'), has_after('Test Teardown Keyword')))), )
def test_fixture_attachment(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_fixture_attachment", has_container(executed_docstring_path.allure_report, has_before("fixture_with_attachment", has_attachment() ) ) ) )
def test_nested_fixtures(executed_docstring_source): """ >>> import pytest If we have two fixtures: >>> @pytest.fixture ... def first_fixture(): ... pass >>> @pytest.fixture ... def second_fixture(): ... pass And one that uses both previous: >>> @pytest.fixture ... def child_fixture(first_fixture, second_fixture): ... pass For next test, allure report will contain all tree fixtures: >>> def test_nested_fixtures_example(child_fixture): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_nested_fixtures_example", has_container(executed_docstring_source.allure_report, has_before("first_fixture")), has_container( executed_docstring_source.allure_report, has_before("second_fixture"), ), has_container( executed_docstring_source.allure_report, has_before("child_fixture"), )))
def test_nested_fixtures(executed_docstring_source): """ >>> import pytest If we have two fixtures: >>> @pytest.fixture ... def first_fixture(): ... pass >>> @pytest.fixture ... def second_fixture(): ... pass And one that uses both previous: >>> @pytest.fixture ... def child_fixture(first_fixture, second_fixture): ... pass For next test, allure report will contain all tree fixtures: >>> def test_nested_fixtures_example(child_fixture): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_nested_fixtures_example", has_container(executed_docstring_source.allure_report, has_before("first_fixture") ), has_container(executed_docstring_source.allure_report, has_before("second_fixture"), ), has_container(executed_docstring_source.allure_report, has_before("child_fixture"), ) ) )
def test_function_scope_parametrized_fixture(param, executed_docstring_source): """ >>> import pytest >>> @pytest.fixture(params=[True, False]) ... def parametrized_fixture(request): ... pass >>> def test_function_scope_parametrized_fixture_example(parametrized_fixture): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_function_scope_parametrized_fixture_example[{param}]".format( param=param), has_parameter("parametrized_fixture", str(param)), has_container(executed_docstring_source.allure_report, has_before("parametrized_fixture"))))
def test_yield_fixture(executed_docstring_source): """ >>> import pytest >>> @pytest.fixture ... def yield_fixture(): ... pass >>> def test_yield_fixture_example(yield_fixture): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_yield_fixture_example", has_container(executed_docstring_source.allure_report, has_before("yield_fixture")), ))
def test_function_scope_parametrized_fixture(param, executed_docstring_source): """ >>> import pytest >>> @pytest.fixture(params=[True, False]) ... def parametrized_fixture(request): ... pass >>> def test_function_scope_parametrized_fixture_example(parametrized_fixture): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_function_scope_parametrized_fixture_example[{param}]".format(param=param), has_parameter("parametrized_fixture", str(param)), has_container(executed_docstring_source.allure_report, has_before("parametrized_fixture") ) ) )
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")), ))
def test_fixture_allure_title_before(allured_testdir): allured_testdir.testdir.makepyfile(""" import pytest import allure @allure.title("Allure fixture title") @pytest.fixture def first_fixture(): pass def test_titled_before_fixture_example(first_fixture): pass """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_titled_before_fixture_example", has_container(allured_testdir.allure_report, has_before("Allure fixture title"))))
def test_function_scope_parametrized_fixture_with_ids( param, executed_docstring_source, request): """ >>> import pytest >>> @pytest.fixture(params=[True, False], ids=["param_true", "param_false"]) ... def parametrized_fixture(request): ... pass >>> def test_function_scope_parametrized_fixture_with_ids_example(parametrized_fixture): ... pass """ test_name = "test_function_scope_parametrized_fixture_with_ids_example[{params_name}]".format( params_name=params_name(request)) assert_that( executed_docstring_source.allure_report, has_test_case( test_name, has_parameter("parametrized_fixture", str(param)), has_container(executed_docstring_source.allure_report, has_before("parametrized_fixture"))))
def test_function_scope_parametrized_fixture_with_ids(param, executed_docstring_source, request): """ >>> import pytest >>> @pytest.fixture(params=[True, False], ids=["param_true", "param_false"]) ... def parametrized_fixture(request): ... pass >>> def test_function_scope_parametrized_fixture_with_ids_example(parametrized_fixture): ... pass """ test_name = "test_function_scope_parametrized_fixture_with_ids_example[{params_name}]".format( params_name=params_name(request)) assert_that(executed_docstring_source.allure_report, has_test_case(test_name, has_parameter("parametrized_fixture", str(param)), has_container(executed_docstring_source.allure_report, has_before("parametrized_fixture") ) ) )