def test_assert_has_calls(mocker):
    from pytest_mock import mock_module
    stub = mocker.stub()
    stub("foo")
    stub.assert_has_calls([mock_module.call("foo")])
    with assert_traceback():
        stub.assert_has_calls([mock_module.call("bar")])
Exemple #2
0
def test_assert_has_calls(mocker):
    from pytest_mock import mock_module
    stub = mocker.stub()
    stub("foo")
    stub.assert_has_calls([mock_module.call("foo")])
    with assert_traceback():
        stub.assert_has_calls([mock_module.call("bar")])
Exemple #3
0
def test_instance_method_by_class_spy(mocker):
    from pytest_mock import mock_module

    class Foo(object):
        def bar(self, arg):
            return arg * 2

    spy = mocker.spy(Foo, 'bar')
    foo = Foo()
    other = Foo()
    assert foo.bar(arg=10) == 20
    assert other.bar(arg=10) == 20
    calls = [mock_module.call(foo, arg=10), mock_module.call(other, arg=10)]
    assert spy.call_args_list == calls
def test_instance_method_by_class_spy(mocker):
    from pytest_mock import mock_module

    class Foo(object):

        def bar(self, arg):
            return arg * 2

    spy = mocker.spy(Foo, 'bar')
    foo = Foo()
    other = Foo()
    assert foo.bar(arg=10) == 20
    assert other.bar(arg=10) == 20
    calls = [mock_module.call(foo, arg=10), mock_module.call(other, arg=10)]
    assert spy.call_args_list == calls