Exemplo n.º 1
0
def test_filter_hook_complexly(mocker):
    # prepare hook mock
    conditions = {
        'test_project_names': ['Foo'],
        'test_suite_names': ['Foo Suite'],
        'test_names': ['Foo Test'],
    }
    hook_mock, hook_func = _create_hook_mock(mocker, conditions,
                                             'pre_test_run')
    mocker.patch('side_runner_py.hook.Config')
    mocker.patch('side_runner_py.hook.load_hook_scripts').return_value = [
        hook_mock
    ]

    # call hook
    hook.run_hook_per_test('pre', None, {'name': 'Foo'}, {'name': 'Foo Suite'},
                           {'name': 'Foo Test'})
    assert hook_func.call_count == 1

    hook.run_hook_per_test('pre', None, {'name': 'Bar'}, {'name': 'Foo Suite'},
                           {'name': 'Foo Test'})
    assert hook_func.call_count == 1

    hook.run_hook_per_test('pre', None, {'name': 'Foo'}, {'name': 'Bar Suite'},
                           {'name': 'Foo Test'})
    assert hook_func.call_count == 1

    hook.run_hook_per_test('pre', None, {'name': 'Foo'}, {'name': 'Foo Suite'},
                           {'name': 'Bar Test'})
    assert hook_func.call_count == 1
Exemplo n.º 2
0
def test_filter_hook_by_test_id(mocker):
    # prepare hook mock
    conditions = {
        'test_project_ids': ['*'],
        'test_suite_ids': ['*'],
        'test_ids': ['ID1'],
    }
    hook_mock, hook_func = _create_hook_mock(mocker, conditions,
                                             'pre_test_run')
    mocker.patch('side_runner_py.hook.Config')
    mocker.patch('side_runner_py.hook.load_hook_scripts').return_value = [
        hook_mock
    ]

    # call hook
    hook.run_hook_per_test('pre', None, {'id': 'ID1'}, {'id': 'ID1'},
                           {'id': 'ID1'})
    assert hook_func.call_count == 1

    hook.run_hook_per_test('pre', None, {'id': 'ID1'}, {'id': 'ID1'},
                           {'id': 'ID2'})
    assert hook_func.call_count == 1

    hook.run_hook_per_test('pre', None, {'id': 'ID2'}, {'id': 'ID2'},
                           {'id': 'ID1'})
    assert hook_func.call_count == 2