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_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()]
                                         )

                                       )
                              )
                )
Beispiel #3
0
 def test_several_steps(self):
     assert_that(
         self.allure_report,
         has_test_case(
             'Several Steps',
             all_of(
                 has_step_with_keyword_log(
                     RobotBasicKeywords.LOG,
                     has_parameter('arg1', 'First Step')),
                 has_step_with_keyword_log(
                     RobotBasicKeywords.LOG,
                     has_parameter('arg1', 'Second Step')),
                 has_step_with_keyword_log(
                     RobotBasicKeywords.LOG,
                     has_parameter('arg1', 'Third Step')),
             )))
def test_parametrized_func(first, second):
    """
    >>> from nose2.tools import params

    >>> @params(("hello", 42), ("world", 777))
    ... def test_parametrized_func_example(alpha, betta):
    ...     pass
    """
    first_param_name, first_param_value = first
    second_param_name, second_param_value = second

    allure_report = run_docstring_example()
    assert_that(
        allure_report,
        has_test_case(
            "test_parametrized_func_example",
            has_parameter(first_param_name, represent(first_param_value)),
            has_parameter(second_param_name, represent(second_param_value))))
def test_parametrization_many_decorators(executed_docstring_source, request,
                                         param1, param2):
    """
    >>> import pytest

    >>> @pytest.mark.parametrize("param1", [True, False])
    ... @pytest.mark.parametrize("param2", [True, True])
    ... def test_parametrization_many_decorators_example(param1, param2):
    ...     pass
    """

    test_name = "test_parametrization_many_decorators_example[{params_name}]".format(
        params_name=params_name(request))

    assert_that(
        executed_docstring_source.allure_report,
        has_test_case(test_name, has_parameter("param1", str(param1)),
                      has_parameter("param2", str(param2))))
    def test_parametrized_method(self, first, second):
        """
        >>> import unittest
        >>> from nose2.tools import params

        >>> class TestParametrizedExample(unittest.TestCase):
        ...     @params(({"hello": 4}, [4, 2]), ({"wold": 2}, [7, 7, 7]))
        ...     def test_parametrized_method_example(self, bravo, charlie):
        ...         pass
        """
        first_param_name, first_param_value = first
        second_param_name, second_param_value = second

        allure_report = run_docstring_example()
        assert_that(
            allure_report,
            has_test_case(
                "test_parametrized_method_example",
                has_parameter(first_param_name, represent(first_param_value)),
                has_parameter(second_param_name,
                              represent(second_param_value))))
def test_parametrization(executed_docstring_source, param):
    """
    >>> import pytest

    >>> @pytest.mark.parametrize("param", [True, False])
    ... def test_parametrization_example(param):
    ...     assert param
    """

    assert_that(
        executed_docstring_source.allure_report,
        has_test_case(
            "test_parametrization_example[{param}]".format(param=param),
            has_parameter("param", str(param))))
def test_parametrization_with_ids(executed_docstring_source, param):
    """
    >>> import pytest

    >>> @pytest.mark.parametrize("param", [True, False], ids=["pass", "fail"])
    ... def test_parametrization_with_ids_example(param):
    ...     assert param
    """

    assert_that(
        executed_docstring_source.allure_report,
        has_test_case(
            "test_parametrization_with_ids_example[{param}]".format(
                param="pass" if param else "fail"),
            has_parameter("pass" if param else "fail", str(param))))
def test_metafunc_param(executed_docstring_source, param):
    """
    >>> def pytest_generate_tests(metafunc):
    ...     if "metafunc_param" in metafunc.fixturenames:
    ...         metafunc.parametrize("metafunc_param", [True, False])


    >>> def test_metafunc_param_example(metafunc_param):
    ...     assert metafunc_param
    """

    assert_that(executed_docstring_source.allure_report,
                has_test_case("test_metafunc_param_example[{param}]".format(param=param),
                              has_parameter("metafunc_param", str(param))
                              )
                )
def test_metafunc_param_with_ids(executed_docstring_source, param):
    """
    >>> def pytest_generate_tests(metafunc):
    ...     if "metafunc_param_with_ids" in metafunc.fixturenames:
    ...         metafunc.parametrize("metafunc_param_with_ids", [True, False], ids=["pass", "fail"])


    >>> def test_metafunc_param_with_ids_example(metafunc_param_with_ids):
    ...     assert metafunc_param_with_ids
    """

    assert_that(executed_docstring_source.allure_report,
                has_test_case("test_metafunc_param_with_ids_example[{param}]".format(param="pass" if param else "fail"),
                              has_parameter("metafunc_param_with_ids", str(param))
                              )
                )
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_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_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")
                                            )
                              )
                )