Ejemplo n.º 1
0
def test_hookregistry_call_hook_func_if_tag_matched(mocker):
    # given
    registry = HookRegistry()

    to_be_called_hook_func = mocker.MagicMock(
        name="before_each_scenario_func_tagged")
    not_to_be_called_hook = mocker.MagicMock(name="before_each_scenario_func")

    registry.register(
        what="each_scenario",
        when="before",
        func=to_be_called_hook_func,
        on_tags=["some-tag"],
        order=1,
    )
    registry.register(
        what="each_scenario",
        when="before",
        func=not_to_be_called_hook,
        on_tags=["another-tag"],
        order=1,
    )

    tagged_model = mocker.MagicMock(name="TaggedModel")
    tagged_model.get_all_tags.return_value = [
        Tag(name="some-tag", path="", line=0)
    ]

    # when
    registry.call("each_scenario", "before", False, tagged_model)

    # then
    to_be_called_hook_func.assert_has_calls([mock.call(mock.ANY)])
    not_to_be_called_hook.assert_has_calls([])
Ejemplo n.º 2
0
def test_hookregistry_call_hook_func_if_match(mocker):
    # given
    registry = HookRegistry()

    to_be_called_hook_func = mocker.MagicMock(name="before_each_scenario_func")
    not_to_be_called_hook = mocker.MagicMock(name="after_each_scenario_func")

    registry.register(
        what="each_scenario",
        when="before",
        func=to_be_called_hook_func,
        on_tags=[],
        order=1,
    )
    registry.register(
        what="each_scenario",
        when="after",
        func=not_to_be_called_hook,
        on_tags=[],
        order=1,
    )

    # when
    registry.call("each_scenario", "before", False,
                  mocker.MagicMock(name="TaggedModel"))

    # then
    to_be_called_hook_func.assert_has_calls([mock.call(mock.ANY)])
    not_to_be_called_hook.assert_has_calls([])