def test_step_with_thread_and_attachment(allured_testdir): allured_testdir.testdir.makepyfile(""" from concurrent.futures import ThreadPoolExecutor import allure import pytest @allure.step("thread {x}") def parallel_step(x=1): allure.attach("text", str(x), allure.attachment_type.TEXT) def test_thread(): with allure.step("Start in thread"): with ThreadPoolExecutor(max_workers=2) as executor: f_result = executor.map(parallel_step, [1, 2]) """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_thread", has_step( "Start in thread", has_step("thread 1", has_attachment(name="1")), has_step("thread 2", has_attachment(name="2")), )))
def test_nested_steps(executed_docstring_path): assert_that( executed_docstring_path.allure_report, has_test_case( "test_nested_steps", has_step("grand parent step", has_step("parent step", has_step("passed_step")))))
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_step_with_thread(allured_testdir): allured_testdir.testdir.makepyfile(""" from concurrent.futures import ThreadPoolExecutor import allure @allure.step("thread {x}") def parallel_step(x=1): with allure.step("Sub-step in thread"): pass def test_thread(): with allure.step("Start in thread"): with ThreadPoolExecutor(max_workers=2) as executor: executor.map(parallel_step, [1, 2]) """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_thread", has_step("Start in thread", has_step("thread 1", has_step("Sub-step in thread")), has_step("thread 2"))))
def test_nested_steps(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_nested_steps", has_step("grand parent step", has_step("parent step", has_step("passed_step" ) ) ) ) )
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_passed_with_multiple_step(self): assert_that( self.allure_report, has_test_case( 'Passed Case With Multiple Step', with_status('passed'), has_step( 'Passed Keyword 1', with_status('passed'), has_step(RobotBasicKeywords.NO_OPERATION, with_status('passed'))), has_step( 'Passed Keyword 2', with_status('passed'), has_step(RobotBasicKeywords.NO_OPERATION, with_status('passed'))), ))
def test_step_parameters(executed_docstring_source, request, args, kwargs): """ >>> import pytest >>> import allure >>> @allure.step ... def step(arg, kwarg=None): ... pass >>> @pytest.mark.parametrize( ... ["args", "kwargs"], ... [ ... ([True], {"kwarg": False}), ... ([True], {"kwarg": False}), ... (["hi"], {"kwarg": None}), ... ([None], {"kwarg": 42}) ... ] ... ) ... def test_args_less_than_placeholders_example(args, kwargs): ... step(*args, **kwargs) """ test_name = "test_args_less_than_placeholders_example[{params_name}]".format( params_name=params_name(request)) assert_that(executed_docstring_source.allure_report, has_test_case(test_name, has_step("step", *([has_parameter("arg", represent(arg)) for arg in args] + [has_parameter("kwarg", represent(kwarg)) for kwarg in kwargs.values()] ) ) ) )
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_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_xfail_step_failure(executed_docstring_source): """ >>> import pytest >>> import allure >>> @pytest.mark.xfail() ... def test_xfail_step_failure_example(): ... with allure.step("Step"): ... assert False """ assert_that(executed_docstring_source.allure_report, has_test_case("test_xfail_step_failure_example", with_status("skipped"), has_status_details(with_message_contains("AssertionError"), with_trace_contains("def test_xfail_step_failure_example():") ), has_step("Step", with_status("failed"), has_status_details(with_message_contains("AssertionError"), with_trace_contains("test_xfail_step_failure_example") ) ) ) )
def test_step_with_attachment(executed_docstring_path): assert_that( executed_docstring_path.allure_report, has_test_case( "test_step_with_attachment", has_step("step_with_attachment", has_attachment()), ))
def test_step_parameters(executed_docstring_source, request, args, kwargs): """ >>> import pytest >>> import allure >>> @allure.step ... def step(arg, kwarg=None): ... pass >>> @pytest.mark.parametrize( ... ["args", "kwargs"], ... [ ... ([True], {"kwarg": False}), ... ([True], {"kwarg": False}), ... (["hi"], {"kwarg": None}), ... ([None], {"kwarg": 42}) ... ] ... ) ... def test_args_less_than_placeholders_example(args, kwargs): ... step(*args, **kwargs) """ test_name = "test_args_less_than_placeholders_example[{params_name}]".format( params_name=params_name(request)) assert_that( executed_docstring_source.allure_report, has_test_case( test_name, has_step( "step", *([has_parameter("arg", represent(arg)) for arg in args] + [ has_parameter("kwarg", represent(kwarg)) for kwarg in kwargs.values() ]))))
def test_pytest_bytes_data_in_assert(executed_docstring_source): """ >>> import allure >>> def test_pytest_bytes_data_in_assert_example(): ... with allure.step("Step"): ... assert "0\\x82" == 1 """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_pytest_bytes_data_in_assert_example", with_status("failed"), has_status_details( with_message_contains( "AssertionError: assert \'0\\x82\' == 1"), with_trace_contains( "def test_pytest_bytes_data_in_assert_example():")), has_step( "Step", with_status("failed"), has_status_details( with_message_contains( "AssertionError: assert \'0\\x82\' == 1"), with_trace_contains( "test_pytest_bytes_data_in_assert_example")))))
def test_step_with_attachment(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_step_with_attachment", has_step("step_with_attachment", has_attachment() ), ) )
def test_call_decorated_as_step_function(executed_docstring_source): """ >>> import allure >>> with allure.step("step outside"): ... pass >>> def test_call_decorated_as_step_function_example(): ... pass """ assert_that( executed_docstring_source.allure_report, has_test_case("test_call_decorated_as_step_function_example", not_(has_step("step outside"))))
def test_call_decorated_as_step_function(executed_docstring_source): """ >>> import allure >>> with allure.step("step outside"): ... pass >>> def test_call_decorated_as_step_function_example(): ... pass """ assert_that(executed_docstring_source.allure_report, has_test_case("test_call_decorated_as_step_function_example", not_(has_step("step outside")) ) )
def test_broken_step(executed_docstring_source): """ >>> import allure >>> def test_broken_step_example(): ... with allure.step("Step"): ... raise ZeroDivisionError """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_broken_step_example", with_status("broken"), has_status_details( with_message_contains("ZeroDivisionError"), with_trace_contains("def test_broken_step_example():")), has_step( "Step", with_status("broken"), has_status_details( with_message_contains("ZeroDivisionError"), with_trace_contains("test_broken_step_example")))))
def test_skip_in_step(executed_docstring_source): """ >>> import pytest >>> import allure >>> def test_skip_in_step_example(): ... with allure.step("Step"): ... pytest.skip() """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_skip_in_step_example", with_status("skipped"), has_status_details( with_message_contains("Skipped: <Skipped instance>")), has_step( "Step", with_status("skipped"), has_status_details( with_message_contains("Skipped: <Skipped instance>"), with_trace_contains("test_skip_in_step")))))
def test_step_from_init_py(allured_testdir): allured_testdir.testdir.makepyfile(__init__=""" import allure @allure.step("function in __init__ marked as step") def step_from__init__(): pass """) allured_testdir.testdir.makepyfile(""" from . import step_from__init__ def test_step_from_init_py_example(): step_from__init__() """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case("test_step_from_init_py_example", has_step("function in __init__ marked as step")))
def test_step_from_init_py(allured_testdir): allured_testdir.testdir.makepyfile(__init__=""" import allure @allure.step("function in __init__ marked as step") def step_from__init__(): pass """) allured_testdir.testdir.makepyfile(""" from . import step_from__init__ def test_step_from_init_py_example(): step_from__init__() """) allured_testdir.run_with_allure() assert_that(allured_testdir.allure_report, has_test_case("test_step_from_init_py_example", has_step("function in __init__ marked as step") ) )
def test_pytest_fail_in_step(executed_docstring_source): """ >>> import pytest >>> import allure >>> def test_pytest_fail_in_step_example(): ... with allure.step("Step"): ... pytest.fail() """ assert_that( executed_docstring_source.allure_report, has_test_case( "test_pytest_fail_in_step_example", with_status("failed"), has_status_details( with_message_contains("Failed"), with_trace_contains( "def test_pytest_fail_in_step_example():")), has_step( "Step", with_status("failed"), has_status_details( with_message_contains("Failed"), with_trace_contains("test_pytest_fail_in_step_example")))))
def test_broken_step(executed_docstring_source): """ >>> import allure >>> def test_broken_step_example(): ... with allure.step("Step"): ... raise ZeroDivisionError """ assert_that(executed_docstring_source.allure_report, has_test_case("test_broken_step_example", with_status("broken"), has_status_details(with_message_contains("ZeroDivisionError"), with_trace_contains("def test_broken_step_example():") ), has_step("Step", with_status("broken"), has_status_details(with_message_contains("ZeroDivisionError"), with_trace_contains("test_broken_step_example") ) ) ) )
def test_pytest_bytes_data_in_assert(executed_docstring_source): """ >>> import allure >>> def test_pytest_bytes_data_in_assert_example(): ... with allure.step("Step"): ... assert "0\\x82" == 1 """ assert_that(executed_docstring_source.allure_report, has_test_case("test_pytest_bytes_data_in_assert_example", with_status("failed"), has_status_details(with_message_contains("AssertionError: assert \'0\\x82\' == 1"), with_trace_contains("def test_pytest_bytes_data_in_assert_example():") ), has_step("Step", with_status("failed"), has_status_details( with_message_contains("AssertionError: assert \'0\\x82\' == 1"), with_trace_contains("test_pytest_bytes_data_in_assert_example") ) ) ) )
def test_pytest_fail_in_step(executed_docstring_source): """ >>> import pytest >>> import allure >>> def test_pytest_fail_in_step_example(): ... with allure.step("Step"): ... pytest.fail() """ assert_that(executed_docstring_source.allure_report, has_test_case("test_pytest_fail_in_step_example", with_status("failed"), has_status_details(with_message_contains("Failed: <Failed instance>"), with_trace_contains("def test_pytest_fail_in_step_example():") ), has_step("Step", with_status("failed"), has_status_details(with_message_contains("Failed: <Failed instance>"), with_trace_contains("test_pytest_fail_in_step_example") ) ) ) )
def test_step_with_reused_threads(allured_testdir): allured_testdir.testdir.makepyfile(""" from concurrent.futures import ThreadPoolExecutor import allure import random from time import sleep @allure.step("thread {x}") def parallel_step(x=1): sleep(random.randint(0, 3)) def test_thread(): with ThreadPoolExecutor(max_workers=2) as executor: executor.map(parallel_step, range(1, 4)) with allure.step("Reuse previous threads"): with ThreadPoolExecutor(max_workers=2) as executor: executor.map(parallel_step, range(1, 4)) """) allured_testdir.run_with_allure() assert_that( allured_testdir.allure_report, has_test_case( "test_thread", has_step("thread 1"), has_step("thread 2"), has_step("thread 3"), has_step( "Reuse previous threads", has_step("thread 1"), has_step("thread 2"), has_step("thread 3"), ), ))
def test_reusable_step(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_reusable_step", has_step("passed_step") ) )
def test_class_method_as_step(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_class_method_as_step", has_step("Class method step with 'first' and 'second'") ) )
def test_step_with_args_in_placeholder(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_step_with_args_in_placeholder", has_step("Step with two args: 'first' and 'second'") ) )
def test_class_method_as_step(executed_docstring_path): assert_that( executed_docstring_path.allure_report, has_test_case("test_class_method_as_step", has_step("Class method step with 'first' and 'second'")))
def has_step_with_keyword_log(step_name, *matchers): return has_step( step_name, has_attachment(attach_type='text/html', name='Keyword Log'), *matchers)
def test_inline_step(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_inline_step", has_step("inline step")))
def test_class_method_as_step(executed_docstring_path): assert_that( executed_docstring_path.allure_report, has_test_case("test_class_method_as_step", has_step("class method as step")))
def test_step_with_args_in_placeholder(executed_docstring_path): assert_that( executed_docstring_path.allure_report, has_test_case("test_step_with_args_in_placeholder", has_step("Step with two args: 'first' and 'second'")))
def test_reusable_step(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_reusable_step", has_step("passed_step")))
def test_class_method_as_step(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_class_method_as_step", has_step("class method as step") ) )
def test_inline_step(executed_docstring_path): assert_that(executed_docstring_path.allure_report, has_test_case("test_inline_step", has_step("inline step") ) )