question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

3.6.0: pytest is failing

See original GitHub issue
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/python3 -Bm pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/tkloczko/rpmbuild/BUILD/pytest-mock-3.6.0, configfile: tox.ini
plugins: mock-3.6.0, forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, hypothesis-6.10.1, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, flaky-3.7.0
collected 72 items

tests/test_pytest_mock.py ................................................FF.......FFF............                                                                   [100%]

================================================================================= FAILURES =================================================================================
________________________________________________________________ test_assert_called_args_with_introspection ________________________________________________________________

__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>, args = (<MagicMock spec='function' id='140136265299184'>, 'b', 2, {'jest'})
kwargs = {}, __tracebackhide__ = True
msg = "expected call not found.\nExpected: mock('b', 2, {'jest'})\nActual: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n"
__mock_self = <MagicMock spec='function' id='140136265299184'>, actual_args = ('a', 1, {'test'}), actual_kwargs = {}, introspection = '\nArgs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

../../BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <MagicMock spec='function' id='140136265299184'>, args = ('b', 2, {'jest'}), kwargs = {}, expected = ('', <BoundArguments (args=('b', 2, {'jest'}))>)
actual = ('', <BoundArguments (args=('a', 1, {'test'}))>), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f7404609a60>
cause = None

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\nActual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)

        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs)
            return msg
        expected = self._call_matcher((args, kwargs))
        actual = self._call_matcher(self.call_args)
        if expected != actual:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected call not found.
E           Expected: mock('b', 2, {'jest'})
E           Actual: mock('a', 1, {'test'})

/usr/lib64/python3.8/unittest/mock.py:913: AssertionError

During handling of the above exception, another exception occurred:

left = ('a', 1, {'test'}), right = ('b', 2, {'jest'})

    @contextmanager
    def assert_argument_introspection(left: Any, right: Any) -> Generator[None, None, None]:
        """
        Assert detailed argument introspection is used
        """
        try:
>           yield

tests/test_pytest_mock.py:509:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f7404503550>

    @pytest.mark.usefixtures("needs_assert_rewrite")
    def test_assert_called_args_with_introspection(mocker: MockerFixture) -> None:
        stub = mocker.stub()

        complex_args = ("a", 1, {"test"})
        wrong_args = ("b", 2, {"jest"})

        stub(*complex_args)
        stub.assert_called_with(*complex_args)
        stub.assert_called_once_with(*complex_args)

        with assert_argument_introspection(complex_args, wrong_args):
>           stub.assert_called_with(*wrong_args)

tests/test_pytest_mock.py:583:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (<MagicMock spec='function' id='140136265299184'>, 'b', 2, {'jest'}), kwargs = {}, __tracebackhide__ = True

    def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None:
        __tracebackhide__ = True
>       assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs)

../../BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:436:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>, args = (<MagicMock spec='function' id='140136265299184'>, 'b', 2, {'jest'})
kwargs = {}, __tracebackhide__ = True
msg = "expected call not found.\nExpected: mock('b', 2, {'jest'})\nActual: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n"
__mock_self = <MagicMock spec='function' id='140136265299184'>, actual_args = ('a', 1, {'test'}), actual_kwargs = {}, introspection = '\nArgs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
            __wrapped_mock_method__(*args, **kwargs)
            return
        except AssertionError as e:
            if getattr(e, "_mock_introspection_applied", 0):
                msg = str(e)
            else:
                __mock_self = args[0]
                msg = str(e)
                if __mock_self.call_args is not None:
                    actual_args, actual_kwargs = __mock_self.call_args
                    introspection = ""
                    try:
                        assert actual_args == args[1:]
                    except AssertionError as e_args:
                        introspection += "\nArgs:\n" + str(e_args)
                    try:
                        assert actual_kwargs == kwargs
                    except AssertionError as e_kwargs:
                        introspection += "\nKwargs:\n" + str(e_kwargs)
                    if introspection:
                        msg += "\n\npytest introspection follows:\n" + introspection
            e = AssertionError(msg)
            e._mock_introspection_applied = True  # type:ignore[attr-defined]
>           raise e
E           AssertionError: expected call not found.
E           Expected: mock('b', 2, {'jest'})
E           Actual: mock('a', 1, {'test'})
E
E           pytest introspection follows:
E
E           Args:

../../BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:426: AssertionError

During handling of the above exception, another exception occurred:

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f7404503550>

    @pytest.mark.usefixtures("needs_assert_rewrite")
    def test_assert_called_args_with_introspection(mocker: MockerFixture) -> None:
        stub = mocker.stub()

        complex_args = ("a", 1, {"test"})
        wrong_args = ("b", 2, {"jest"})

        stub(*complex_args)
        stub.assert_called_with(*complex_args)
        stub.assert_called_once_with(*complex_args)

        with assert_argument_introspection(complex_args, wrong_args):
            stub.assert_called_with(*wrong_args)
>           stub.assert_called_once_with(*wrong_args)

tests/test_pytest_mock.py:584:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib64/python3.8/contextlib.py:131: in __exit__
    self.gen.throw(type, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

left = ('a', 1, {'test'}), right = ('b', 2, {'jest'})

    @contextmanager
    def assert_argument_introspection(left: Any, right: Any) -> Generator[None, None, None]:
        """
        Assert detailed argument introspection is used
        """
        try:
            yield
        except AssertionError as e:
            # this may be a bit too assuming, but seems nicer then hard-coding
            import _pytest.assertion.util as util

            # NOTE: we assert with either verbose or not, depending on how our own
            #       test was run by examining sys.argv
            verbose = any(a.startswith("-v") for a in sys.argv)
            expected = "\n  ".join(util._compare_eq_iterable(left, right, verbose))
>           assert expected in str(e)
E           assert 'Use -v to get the full diff' in "expected call not found.\nExpected: mock('b', 2, {'jest'})\nActual: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n"
E            +  where "expected call not found.\nExpected: mock('b', 2, {'jest'})\nActual: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n" = str(AssertionError("expected call not found.\nExpected: mock('b', 2, {'jest'})\nActual: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n"))

tests/test_pytest_mock.py:518: AssertionError
_______________________________________________________________ test_assert_called_kwargs_with_introspection _______________________________________________________________

__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>, args = (<MagicMock spec='function' id='140136266474976'>,)
kwargs = {'foo': {'baz': 'bran', 'goo': 1}}, __tracebackhide__ = True
msg = "expected call not found.\nExpected: mock(foo={'goo': 1, 'baz': 'bran'})\nActual: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n"
__mock_self = <MagicMock spec='function' id='140136266474976'>, actual_args = (), actual_kwargs = {'foo': {'bar': 1, 'baz': 'spam'}}, introspection = '\nKwargs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

../../BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <MagicMock spec='function' id='140136266474976'>, args = (), kwargs = {'foo': {'baz': 'bran', 'goo': 1}}
expected = ('', <BoundArguments (kwargs={'foo': {'goo': 1, 'baz': 'bran'}})>), actual = ('', <BoundArguments (kwargs={'foo': {'bar': 1, 'baz': 'spam'}})>)
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f7404609940>, cause = None

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\nActual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)

        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs)
            return msg
        expected = self._call_matcher((args, kwargs))
        actual = self._call_matcher(self.call_args)
        if expected != actual:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected call not found.
E           Expected: mock(foo={'goo': 1, 'baz': 'bran'})
E           Actual: mock(foo={'bar': 1, 'baz': 'spam'})

/usr/lib64/python3.8/unittest/mock.py:913: AssertionError

During handling of the above exception, another exception occurred:

left = {'foo': {'bar': 1, 'baz': 'spam'}}, right = {'foo': {'baz': 'bran', 'goo': 1}}

    @contextmanager
    def assert_argument_introspection(left: Any, right: Any) -> Generator[None, None, None]:
        """
        Assert detailed argument introspection is used
        """
        try:
>           yield

tests/test_pytest_mock.py:509:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f74046227f0>

    @pytest.mark.usefixtures("needs_assert_rewrite")
    def test_assert_called_kwargs_with_introspection(mocker: MockerFixture) -> None:
        stub = mocker.stub()

        complex_kwargs = dict(foo={"bar": 1, "baz": "spam"})
        wrong_kwargs = dict(foo={"goo": 1, "baz": "bran"})

        stub(**complex_kwargs)
        stub.assert_called_with(**complex_kwargs)
        stub.assert_called_once_with(**complex_kwargs)

        with assert_argument_introspection(complex_kwargs, wrong_kwargs):
>           stub.assert_called_with(**wrong_kwargs)

tests/test_pytest_mock.py:599:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (<MagicMock spec='function' id='140136266474976'>,), kwargs = {'foo': {'baz': 'bran', 'goo': 1}}, __tracebackhide__ = True

    def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None:
        __tracebackhide__ = True
>       assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs)

../../BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:436:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>, args = (<MagicMock spec='function' id='140136266474976'>,)
kwargs = {'foo': {'baz': 'bran', 'goo': 1}}, __tracebackhide__ = True
msg = "expected call not found.\nExpected: mock(foo={'goo': 1, 'baz': 'bran'})\nActual: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n"
__mock_self = <MagicMock spec='function' id='140136266474976'>, actual_args = (), actual_kwargs = {'foo': {'bar': 1, 'baz': 'spam'}}, introspection = '\nKwargs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
            __wrapped_mock_method__(*args, **kwargs)
            return
        except AssertionError as e:
            if getattr(e, "_mock_introspection_applied", 0):
                msg = str(e)
            else:
                __mock_self = args[0]
                msg = str(e)
                if __mock_self.call_args is not None:
                    actual_args, actual_kwargs = __mock_self.call_args
                    introspection = ""
                    try:
                        assert actual_args == args[1:]
                    except AssertionError as e_args:
                        introspection += "\nArgs:\n" + str(e_args)
                    try:
                        assert actual_kwargs == kwargs
                    except AssertionError as e_kwargs:
                        introspection += "\nKwargs:\n" + str(e_kwargs)
                    if introspection:
                        msg += "\n\npytest introspection follows:\n" + introspection
            e = AssertionError(msg)
            e._mock_introspection_applied = True  # type:ignore[attr-defined]
>           raise e
E           AssertionError: expected call not found.
E           Expected: mock(foo={'goo': 1, 'baz': 'bran'})
E           Actual: mock(foo={'bar': 1, 'baz': 'spam'})
E
E           pytest introspection follows:
E
E           Kwargs:

../../BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:426: AssertionError

During handling of the above exception, another exception occurred:

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f74046227f0>

    @pytest.mark.usefixtures("needs_assert_rewrite")
    def test_assert_called_kwargs_with_introspection(mocker: MockerFixture) -> None:
        stub = mocker.stub()

        complex_kwargs = dict(foo={"bar": 1, "baz": "spam"})
        wrong_kwargs = dict(foo={"goo": 1, "baz": "bran"})

        stub(**complex_kwargs)
        stub.assert_called_with(**complex_kwargs)
        stub.assert_called_once_with(**complex_kwargs)

        with assert_argument_introspection(complex_kwargs, wrong_kwargs):
            stub.assert_called_with(**wrong_kwargs)
>           stub.assert_called_once_with(**wrong_kwargs)

tests/test_pytest_mock.py:600:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib64/python3.8/contextlib.py:131: in __exit__
    self.gen.throw(type, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

left = {'foo': {'bar': 1, 'baz': 'spam'}}, right = {'foo': {'baz': 'bran', 'goo': 1}}

    @contextmanager
    def assert_argument_introspection(left: Any, right: Any) -> Generator[None, None, None]:
        """
        Assert detailed argument introspection is used
        """
        try:
            yield
        except AssertionError as e:
            # this may be a bit too assuming, but seems nicer then hard-coding
            import _pytest.assertion.util as util

            # NOTE: we assert with either verbose or not, depending on how our own
            #       test was run by examining sys.argv
            verbose = any(a.startswith("-v") for a in sys.argv)
            expected = "\n  ".join(util._compare_eq_iterable(left, right, verbose))
>           assert expected in str(e)
E           assert 'Use -v to get the full diff' in "expected call not found.\nExpected: mock(foo={'goo': 1, 'baz': 'bran'})\nActual: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n"
E            +  where "expected call not found.\nExpected: mock(foo={'goo': 1, 'baz': 'bran'})\nActual: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n" = str(AssertionError("expected call not found.\nExpected: mock(foo={'goo': 1, 'baz': 'bran'})\nActual: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n"))

tests/test_pytest_mock.py:518: AssertionError
___________________________________________________________________________ test_standalone_mock ___________________________________________________________________________

testdir = <Testdir local('/tmp/pytest-of-tkloczko/pytest-1/test_standalone_mock0')>

    def test_standalone_mock(testdir: Any) -> None:
        """Check that the "mock_use_standalone" is being used."""
        testdir.makepyfile(
            """
            def test_foo(mocker):
                pass
        """
        )
        testdir.makeini(
            """
            [pytest]
            mock_use_standalone_module = true
        """
        )
        result = testdir.runpytest_subprocess()
>       assert result.ret == 3
E       assert <ExitCode.OK: 0> == 3
E        +  where <ExitCode.OK: 0> = <RunResult ret=ExitCode.OK len(stdout.lines)=9 len(stderr.lines)=0 duration=2.37s>.ret

/home/tkloczko/rpmbuild/BUILD/pytest-mock-3.6.0/tests/test_pytest_mock.py:721: AssertionError
--------------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------------
running: /usr/bin/python3 -mpytest --basetemp=/tmp/pytest-of-tkloczko/pytest-1/test_standalone_mock0/runpytest-0
     in: /tmp/pytest-of-tkloczko/pytest-1/test_standalone_mock0
============================= test session starts ==============================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/pytest-of-tkloczko/pytest-1/test_standalone_mock0, configfile: tox.ini
plugins: mock-3.6.0, forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, hypothesis-6.10.1, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, flaky-3.7.0
collected 1 item

test_standalone_mock.py .                                                [100%]

============================== 1 passed in 0.03s ===============================
_______________________________________________________________________ test_detailed_introspection ________________________________________________________________________

testdir = <Testdir local('/tmp/pytest-of-tkloczko/pytest-1/test_detailed_introspection0')>

    @pytest.mark.usefixtures("needs_assert_rewrite")
    def test_detailed_introspection(testdir: Any) -> None:
        """Check that the "mock_use_standalone" is being used."""
        testdir.makepyfile(
            """
            def test(mocker):
                m = mocker.Mock()
                m('fo')
                m.assert_called_once_with('', bar=4)
        """
        )
        result = testdir.runpytest("-s")
        if NEW_FORMATTING:
            expected_lines = [
                "*AssertionError: expected call not found.",
                "*Expected: mock('', bar=4)",
                "*Actual: mock('fo')",
            ]
        else:
            expected_lines = [
                "*AssertionError: Expected call: mock('', bar=4)*",
                "*Actual call: mock('fo')*",
            ]
        expected_lines += [
            "*pytest introspection follows:*",
            "*Args:",
            "*assert ('fo',) == ('',)",
            "*At index 0 diff: 'fo' != ''*",
            "*Use -v to get the full diff*",
            "*Kwargs:*",
            "*assert {} == {'bar': 4}*",
            "*Right contains* more item*",
            "*{'bar': 4}*",
            "*Use -v to get the full diff*",
        ]
>       result.stdout.fnmatch_lines(expected_lines)
E       Failed: nomatch: '*AssertionError: expected call not found.'
E           and: '============================= test session starts =============================='
E           and: 'platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1'
E           and: 'rootdir: /tmp/pytest-of-tkloczko/pytest-1/test_detailed_introspection0'
E           and: 'plugins: mock-3.6.0, forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, hypothesis-6.10.1, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, flaky-3.7.0'
E           and: 'collected 1 item'
E           and: ''
E           and: 'test_detailed_introspection.py F'
E           and: ''
E           and: '=================================== FAILURES ==================================='
E           and: '_____________________________________ test _____________________________________'
E           and: ''
E           and: '__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>'
E           and: "args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E           and: 'msg = "expected call not found.\\nExpected: mock(\'\', bar=4)\\nActual: mock(\'fo\')\\n\\npytest introspection follows:\\n\\nArgs:\\n\\nKwargs:\\n"'
E           and: "__mock_self = <Mock id='140136266498592'>, actual_args = ('fo',)"
E           and: "actual_kwargs = {}, introspection = '\\nArgs:\\n\\nKwargs:\\n'"
E           and: ''
E           and: '    def assert_wrapper('
E           and: '        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any'
E           and: '    ) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '        try:'
E           and: '>           __wrapped_mock_method__(*args, **kwargs)'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: "self = <Mock id='140136266498592'>, args = ('',), kwargs = {'bar': 4}"
E           and: "expected = (('',), {'bar': 4}), actual = call('fo')"
E           and: '_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f7404707b80>'
E           and: 'cause = None'
E           and: ''
E           and: '    def assert_called_with(self, /, *args, **kwargs):'
E           and: '        """assert that the last call was made with the specified arguments.'
E           and: '    '
E           and: '        Raises an AssertionError if the args and keyword args passed in are'
E           and: '        different to the last call to the mock."""'
E           and: '        if self.call_args is None:'
E           and: '            expected = self._format_mock_call_signature(args, kwargs)'
E           and: "            actual = 'not called.'"
E           and: "            error_message = ('expected call not found.\\nExpected: %s\\nActual: %s'"
E           and: '                    % (expected, actual))'
E           and: '            raise AssertionError(error_message)'
E           and: '    '
E           and: '        def _error_message():'
E           and: '            msg = self._format_mock_failure_message(args, kwargs)'
E           and: '            return msg'
E           and: '        expected = self._call_matcher((args, kwargs))'
E           and: '        actual = self._call_matcher(self.call_args)'
E           and: '        if expected != actual:'
E           and: '            cause = expected if isinstance(expected, Exception) else None'
E           and: '>           raise AssertionError(_error_message()) from cause'
E       fnmatch: '*AssertionError: expected call not found.'
E          with: 'E           AssertionError: expected call not found.'
E       fnmatch: "*Expected: mock('', bar=4)"
E          with: "E           Expected: mock('', bar=4)"
E       fnmatch: "*Actual: mock('fo')"
E          with: "E           Actual: mock('fo')"
E       nomatch: '*pytest introspection follows:*'
E           and: ''
E           and: '/usr/lib64/python3.8/unittest/mock.py:913: AssertionError'
E           and: ''
E           and: 'During handling of the above exception, another exception occurred:'
E           and: ''
E           and: '__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x7f759b50eb80>'
E           and: "args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E       fnmatch: '*pytest introspection follows:*'
E          with: 'msg = "expected call not found.\\nExpected: mock(\'\', bar=4)\\nActual: mock(\'fo\')\\n\\npytest introspection follows:\\n\\nArgs:\\n\\nKwargs:\\n"'
E       nomatch: '*Args:'
E           and: ''
E           and: '    def assert_wrapper('
E           and: '        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any'
E           and: '    ) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '        try:'
E           and: '>           __wrapped_mock_method__(*args, **kwargs)'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: "self = <Mock id='140136266498592'>, args = ('',), kwargs = {'bar': 4}"
E           and: ''
E           and: '    def assert_called_once_with(self, /, *args, **kwargs):'
E           and: '        """assert that the mock was called exactly once and that that call was'
E           and: '        with the specified arguments."""'
E           and: '        if not self.call_count == 1:'
E           and: '            msg = ("Expected \'%s\' to be called once. Called %s times.%s"'
E           and: "                   % (self._mock_name or 'mock',"
E           and: '                      self.call_count,'
E           and: '                      self._calls_repr()))'
E           and: '            raise AssertionError(msg)'
E           and: '>       return self.assert_called_with(*args, **kwargs)'
E           and: ''
E           and: '/usr/lib64/python3.8/unittest/mock.py:925: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: "args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E           and: ''
E           and: '    def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '>       assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs)'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:436: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: '__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>'
E           and: "args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E           and: 'msg = "expected call not found.\\nExpected: mock(\'\', bar=4)\\nActual: mock(\'fo\')\\n\\npytest introspection follows:\\n\\nArgs:\\n\\nKwargs:\\n"'
E           and: "__mock_self = <Mock id='140136266498592'>, actual_args = ('fo',)"
E           and: "actual_kwargs = {}, introspection = '\\nArgs:\\n\\nKwargs:\\n'"
E           and: ''
E           and: '    def assert_wrapper('
E           and: '        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any'
E           and: '    ) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '        try:'
E           and: '            __wrapped_mock_method__(*args, **kwargs)'
E           and: '            return'
E           and: '        except AssertionError as e:'
E           and: '            if getattr(e, "_mock_introspection_applied", 0):'
E           and: '                msg = str(e)'
E           and: '            else:'
E           and: '                __mock_self = args[0]'
E           and: '                msg = str(e)'
E           and: '                if __mock_self.call_args is not None:'
E           and: '                    actual_args, actual_kwargs = __mock_self.call_args'
E           and: '                    introspection = ""'
E           and: '                    try:'
E           and: '                        assert actual_args == args[1:]'
E           and: '                    except AssertionError as e_args:'
E           and: '                        introspection += "\\nArgs:\\n" + str(e_args)'
E           and: '                    try:'
E           and: '                        assert actual_kwargs == kwargs'
E           and: '                    except AssertionError as e_kwargs:'
E           and: '                        introspection += "\\nKwargs:\\n" + str(e_kwargs)'
E           and: '                    if introspection:'
E           and: '                        msg += "\\n\\npytest introspection follows:\\n" + introspection'
E           and: '            e = AssertionError(msg)'
E           and: '            e._mock_introspection_applied = True  # type:ignore[attr-defined]'
E           and: '>           raise e'
E           and: 'E           AssertionError: expected call not found.'
E           and: "E           Expected: mock('', bar=4)"
E           and: "E           Actual: mock('fo')"
E           and: 'E           '
E           and: 'E           pytest introspection follows:'
E           and: 'E           '
E       fnmatch: '*Args:'
E          with: 'E           Args:'
E       nomatch: "*assert ('fo',) == ('',)"
E           and: 'E           '
E           and: 'E           Kwargs:'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:426: AssertionError'
E           and: ''
E           and: 'During handling of the above exception, another exception occurred:'
E           and: ''
E           and: 'mocker = <pytest_mock.plugin.MockerFixture object at 0x7f7404628e20>'
E           and: ''
E           and: '    def test(mocker):'
E           and: '        m = mocker.Mock()'
E           and: "        m('fo')"
E           and: ">       m.assert_called_once_with('', bar=4)"
E           and: 'E       AssertionError: expected call not found.'
E           and: "E       Expected: mock('', bar=4)"
E           and: "E       Actual: mock('fo')"
E           and: 'E       '
E           and: 'E       pytest introspection follows:'
E           and: 'E       '
E           and: 'E       Args:'
E           and: 'E       '
E           and: 'E       Kwargs:'
E           and: ''
E           and: 'test_detailed_introspection.py:4: AssertionError'
E           and: '=========================== short test summary info ============================'
E           and: 'FAILED test_detailed_introspection.py::test - AssertionError: expected call n...'
E           and: '============================== 1 failed in 0.12s ==============================='
E       remains unmatched: "*assert ('fo',) == ('',)"

/home/tkloczko/rpmbuild/BUILD/pytest-mock-3.6.0/tests/test_pytest_mock.py:760: Failed
--------------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------------
============================= test session starts ==============================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/pytest-of-tkloczko/pytest-1/test_detailed_introspection0
plugins: mock-3.6.0, forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, hypothesis-6.10.1, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, flaky-3.7.0
collected 1 item

test_detailed_introspection.py F

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>
args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True
msg = "expected call not found.\nExpected: mock('', bar=4)\nActual: mock('fo')\n\npytest introspection follows:\n\nArgs:\n\nKwargs:\n"
__mock_self = <Mock id='140136266498592'>, actual_args = ('fo',)
actual_kwargs = {}, introspection = '\nArgs:\n\nKwargs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Mock id='140136266498592'>, args = ('',), kwargs = {'bar': 4}
expected = (('',), {'bar': 4}), actual = call('fo')
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f7404707b80>
cause = None

    def assert_called_with(self, /, *args, **kwargs):
        """assert that the last call was made with the specified arguments.

        Raises an AssertionError if the args and keyword args passed in are
        different to the last call to the mock."""
        if self.call_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            actual = 'not called.'
            error_message = ('expected call not found.\nExpected: %s\nActual: %s'
                    % (expected, actual))
            raise AssertionError(error_message)

        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs)
            return msg
        expected = self._call_matcher((args, kwargs))
        actual = self._call_matcher(self.call_args)
        if expected != actual:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected call not found.
E           Expected: mock('', bar=4)
E           Actual: mock('fo')

/usr/lib64/python3.8/unittest/mock.py:913: AssertionError

During handling of the above exception, another exception occurred:

__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x7f759b50eb80>
args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True
msg = "expected call not found.\nExpected: mock('', bar=4)\nActual: mock('fo')\n\npytest introspection follows:\n\nArgs:\n\nKwargs:\n"

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <Mock id='140136266498592'>, args = ('',), kwargs = {'bar': 4}

    def assert_called_once_with(self, /, *args, **kwargs):
        """assert that the mock was called exactly once and that that call was
        with the specified arguments."""
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
            raise AssertionError(msg)
>       return self.assert_called_with(*args, **kwargs)

/usr/lib64/python3.8/unittest/mock.py:925:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True

    def wrap_assert_called_with(*args: Any, **kwargs: Any) -> None:
        __tracebackhide__ = True
>       assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs)

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:436:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

__wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f759b50eaf0>
args = (<Mock id='140136266498592'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True
msg = "expected call not found.\nExpected: mock('', bar=4)\nActual: mock('fo')\n\npytest introspection follows:\n\nArgs:\n\nKwargs:\n"
__mock_self = <Mock id='140136266498592'>, actual_args = ('fo',)
actual_kwargs = {}, introspection = '\nArgs:\n\nKwargs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
            __wrapped_mock_method__(*args, **kwargs)
            return
        except AssertionError as e:
            if getattr(e, "_mock_introspection_applied", 0):
                msg = str(e)
            else:
                __mock_self = args[0]
                msg = str(e)
                if __mock_self.call_args is not None:
                    actual_args, actual_kwargs = __mock_self.call_args
                    introspection = ""
                    try:
                        assert actual_args == args[1:]
                    except AssertionError as e_args:
                        introspection += "\nArgs:\n" + str(e_args)
                    try:
                        assert actual_kwargs == kwargs
                    except AssertionError as e_kwargs:
                        introspection += "\nKwargs:\n" + str(e_kwargs)
                    if introspection:
                        msg += "\n\npytest introspection follows:\n" + introspection
            e = AssertionError(msg)
            e._mock_introspection_applied = True  # type:ignore[attr-defined]
>           raise e
E           AssertionError: expected call not found.
E           Expected: mock('', bar=4)
E           Actual: mock('fo')
E
E           pytest introspection follows:
E
E           Args:
E
E           Kwargs:

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:426: AssertionError

During handling of the above exception, another exception occurred:

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f7404628e20>

    def test(mocker):
        m = mocker.Mock()
        m('fo')
>       m.assert_called_once_with('', bar=4)
E       AssertionError: expected call not found.
E       Expected: mock('', bar=4)
E       Actual: mock('fo')
E
E       pytest introspection follows:
E
E       Args:
E
E       Kwargs:

test_detailed_introspection.py:4: AssertionError
=========================== short test summary info ============================
FAILED test_detailed_introspection.py::test - AssertionError: expected call n...
============================== 1 failed in 0.12s ===============================
____________________________________________________________________ test_detailed_introspection_async _____________________________________________________________________

testdir = <Testdir local('/tmp/pytest-of-tkloczko/pytest-1/test_detailed_introspection_async0')>

    @pytest.mark.skipif(
        sys.version_info < (3, 8), reason="AsyncMock is present on 3.8 and above"
    )
    @pytest.mark.usefixtures("needs_assert_rewrite")
    def test_detailed_introspection_async(testdir: Any) -> None:
        """Check that the "mock_use_standalone" is being used."""
        testdir.makepyfile(
            """
            import pytest

            @pytest.mark.asyncio
            async def test(mocker):
                m = mocker.AsyncMock()
                await m('fo')
                m.assert_awaited_once_with('', bar=4)
        """
        )
        result = testdir.runpytest("-s")
        expected_lines = [
            "*AssertionError: expected await not found.",
            "*Expected: mock('', bar=4)",
            "*Actual: mock('fo')",
            "*pytest introspection follows:*",
            "*Args:",
            "*assert ('fo',) == ('',)",
            "*At index 0 diff: 'fo' != ''*",
            "*Use -v to get the full diff*",
            "*Kwargs:*",
            "*assert {} == {'bar': 4}*",
            "*Right contains* more item*",
            "*{'bar': 4}*",
            "*Use -v to get the full diff*",
        ]
>       result.stdout.fnmatch_lines(expected_lines)
E       Failed: nomatch: '*AssertionError: expected await not found.'
E           and: '============================= test session starts =============================='
E           and: 'platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1'
E           and: 'rootdir: /tmp/pytest-of-tkloczko/pytest-1/test_detailed_introspection_async0'
E           and: 'plugins: mock-3.6.0, forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, hypothesis-6.10.1, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, flaky-3.7.0'
E           and: 'collected 1 item'
E           and: ''
E           and: 'test_detailed_introspection_async.py F'
E           and: ''
E           and: '=================================== FAILURES ==================================='
E           and: '_____________________________________ test _____________________________________'
E           and: ''
E           and: '__wrapped_mock_method__ = <function AsyncMockMixin.assert_awaited_with at 0x7f759b5173a0>'
E           and: "args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E           and: 'msg = "expected await not found.\\nExpected: mock(\'\', bar=4)\\nActual: mock(\'fo\')\\n\\npytest introspection follows:\\n\\nArgs:\\n\\nKwargs:\\n"'
E           and: "__mock_self = <AsyncMock id='140136262204192'>, actual_args = ('fo',)"
E           and: "actual_kwargs = {}, introspection = '\\nArgs:\\n\\nKwargs:\\n'"
E           and: ''
E           and: '    def assert_wrapper('
E           and: '        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any'
E           and: '    ) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '        try:'
E           and: '>           __wrapped_mock_method__(*args, **kwargs)'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: "self = <AsyncMock id='140136262204192'>, args = ('',), kwargs = {'bar': 4}"
E           and: "expected = (('',), {'bar': 4})"
E           and: '_error_message = <function AsyncMockMixin.assert_awaited_with.<locals>._error_message at 0x7f740475e310>'
E           and: "actual = call('fo'), cause = None"
E           and: ''
E           and: '    def assert_awaited_with(self, /, *args, **kwargs):'
E           and: '        """'
E           and: '        Assert that the last await was with the specified arguments.'
E           and: '        """'
E           and: '        if self.await_args is None:'
E           and: '            expected = self._format_mock_call_signature(args, kwargs)'
E           and: "            raise AssertionError(f'Expected await: {expected}\\nNot awaited')"
E           and: '    '
E           and: '        def _error_message():'
E           and: "            msg = self._format_mock_failure_message(args, kwargs, action='await')"
E           and: '            return msg'
E           and: '    '
E           and: '        expected = self._call_matcher((args, kwargs))'
E           and: '        actual = self._call_matcher(self.await_args)'
E           and: '        if expected != actual:'
E           and: '            cause = expected if isinstance(expected, Exception) else None'
E           and: '>           raise AssertionError(_error_message()) from cause'
E       fnmatch: '*AssertionError: expected await not found.'
E          with: 'E           AssertionError: expected await not found.'
E       fnmatch: "*Expected: mock('', bar=4)"
E          with: "E           Expected: mock('', bar=4)"
E       fnmatch: "*Actual: mock('fo')"
E          with: "E           Actual: mock('fo')"
E       nomatch: '*pytest introspection follows:*'
E           and: ''
E           and: '/usr/lib64/python3.8/unittest/mock.py:2186: AssertionError'
E           and: ''
E           and: 'During handling of the above exception, another exception occurred:'
E           and: ''
E           and: '__wrapped_mock_method__ = <function AsyncMockMixin.assert_awaited_once_with at 0x7f759b517430>'
E           and: "args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E       fnmatch: '*pytest introspection follows:*'
E          with: 'msg = "expected await not found.\\nExpected: mock(\'\', bar=4)\\nActual: mock(\'fo\')\\n\\npytest introspection follows:\\n\\nArgs:\\n\\nKwargs:\\n"'
E       nomatch: '*Args:'
E           and: ''
E           and: '    def assert_wrapper('
E           and: '        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any'
E           and: '    ) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '        try:'
E           and: '>           __wrapped_mock_method__(*args, **kwargs)'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: "self = <AsyncMock id='140136262204192'>, args = ('',), kwargs = {'bar': 4}"
E           and: ''
E           and: '    def assert_awaited_once_with(self, /, *args, **kwargs):'
E           and: '        """'
E           and: '        Assert that the mock was awaited exactly once and with the specified'
E           and: '        arguments.'
E           and: '        """'
E           and: '        if not self.await_count == 1:'
E           and: '            msg = (f"Expected {self._mock_name or \'mock\'} to have been awaited once."'
E           and: '                   f" Awaited {self.await_count} times.")'
E           and: '            raise AssertionError(msg)'
E           and: '>       return self.assert_awaited_with(*args, **kwargs)'
E           and: ''
E           and: '/usr/lib64/python3.8/unittest/mock.py:2197: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: "args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E           and: ''
E           and: '    def wrap_assert_awaited_with(*args: Any, **kwargs: Any) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '>       assert_wrapper(_mock_module_originals["assert_awaited_with"], *args, **kwargs)'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:471: '
E           and: '_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ '
E           and: ''
E           and: '__wrapped_mock_method__ = <function AsyncMockMixin.assert_awaited_with at 0x7f759b5173a0>'
E           and: "args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}"
E           and: '__tracebackhide__ = True'
E           and: 'msg = "expected await not found.\\nExpected: mock(\'\', bar=4)\\nActual: mock(\'fo\')\\n\\npytest introspection follows:\\n\\nArgs:\\n\\nKwargs:\\n"'
E           and: "__mock_self = <AsyncMock id='140136262204192'>, actual_args = ('fo',)"
E           and: "actual_kwargs = {}, introspection = '\\nArgs:\\n\\nKwargs:\\n'"
E           and: ''
E           and: '    def assert_wrapper('
E           and: '        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any'
E           and: '    ) -> None:'
E           and: '        __tracebackhide__ = True'
E           and: '        try:'
E           and: '            __wrapped_mock_method__(*args, **kwargs)'
E           and: '            return'
E           and: '        except AssertionError as e:'
E           and: '            if getattr(e, "_mock_introspection_applied", 0):'
E           and: '                msg = str(e)'
E           and: '            else:'
E           and: '                __mock_self = args[0]'
E           and: '                msg = str(e)'
E           and: '                if __mock_self.call_args is not None:'
E           and: '                    actual_args, actual_kwargs = __mock_self.call_args'
E           and: '                    introspection = ""'
E           and: '                    try:'
E           and: '                        assert actual_args == args[1:]'
E           and: '                    except AssertionError as e_args:'
E           and: '                        introspection += "\\nArgs:\\n" + str(e_args)'
E           and: '                    try:'
E           and: '                        assert actual_kwargs == kwargs'
E           and: '                    except AssertionError as e_kwargs:'
E           and: '                        introspection += "\\nKwargs:\\n" + str(e_kwargs)'
E           and: '                    if introspection:'
E           and: '                        msg += "\\n\\npytest introspection follows:\\n" + introspection'
E           and: '            e = AssertionError(msg)'
E           and: '            e._mock_introspection_applied = True  # type:ignore[attr-defined]'
E           and: '>           raise e'
E           and: 'E           AssertionError: expected await not found.'
E           and: "E           Expected: mock('', bar=4)"
E           and: "E           Actual: mock('fo')"
E           and: 'E           '
E           and: 'E           pytest introspection follows:'
E           and: 'E           '
E       fnmatch: '*Args:'
E          with: 'E           Args:'
E       nomatch: "*assert ('fo',) == ('',)"
E           and: 'E           '
E           and: 'E           Kwargs:'
E           and: ''
E           and: '/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:426: AssertionError'
E           and: ''
E           and: 'During handling of the above exception, another exception occurred:'
E           and: ''
E           and: 'mocker = <pytest_mock.plugin.MockerFixture object at 0x7f740420fa30>'
E           and: ''
E           and: '    @pytest.mark.asyncio'
E           and: '    async def test(mocker):'
E           and: '        m = mocker.AsyncMock()'
E           and: "        await m('fo')"
E           and: ">       m.assert_awaited_once_with('', bar=4)"
E           and: 'E       AssertionError: expected await not found.'
E           and: "E       Expected: mock('', bar=4)"
E           and: "E       Actual: mock('fo')"
E           and: 'E       '
E           and: 'E       pytest introspection follows:'
E           and: 'E       '
E           and: 'E       Args:'
E           and: 'E       '
E           and: 'E       Kwargs:'
E           and: ''
E           and: 'test_detailed_introspection_async.py:7: AssertionError'
E           and: '=========================== short test summary info ============================'
E           and: 'FAILED test_detailed_introspection_async.py::test - AssertionError: expected ...'
E           and: '============================== 1 failed in 0.19s ==============================='
E       remains unmatched: "*assert ('fo',) == ('',)"

/home/tkloczko/rpmbuild/BUILD/pytest-mock-3.6.0/tests/test_pytest_mock.py:796: Failed
--------------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------------
============================= test session starts ==============================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /tmp/pytest-of-tkloczko/pytest-1/test_detailed_introspection_async0
plugins: mock-3.6.0, forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, asyncio-0.14.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, hypothesis-6.10.1, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, flaky-3.7.0
collected 1 item

test_detailed_introspection_async.py F

=================================== FAILURES ===================================
_____________________________________ test _____________________________________

__wrapped_mock_method__ = <function AsyncMockMixin.assert_awaited_with at 0x7f759b5173a0>
args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True
msg = "expected await not found.\nExpected: mock('', bar=4)\nActual: mock('fo')\n\npytest introspection follows:\n\nArgs:\n\nKwargs:\n"
__mock_self = <AsyncMock id='140136262204192'>, actual_args = ('fo',)
actual_kwargs = {}, introspection = '\nArgs:\n\nKwargs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <AsyncMock id='140136262204192'>, args = ('',), kwargs = {'bar': 4}
expected = (('',), {'bar': 4})
_error_message = <function AsyncMockMixin.assert_awaited_with.<locals>._error_message at 0x7f740475e310>
actual = call('fo'), cause = None

    def assert_awaited_with(self, /, *args, **kwargs):
        """
        Assert that the last await was with the specified arguments.
        """
        if self.await_args is None:
            expected = self._format_mock_call_signature(args, kwargs)
            raise AssertionError(f'Expected await: {expected}\nNot awaited')

        def _error_message():
            msg = self._format_mock_failure_message(args, kwargs, action='await')
            return msg

        expected = self._call_matcher((args, kwargs))
        actual = self._call_matcher(self.await_args)
        if expected != actual:
            cause = expected if isinstance(expected, Exception) else None
>           raise AssertionError(_error_message()) from cause
E           AssertionError: expected await not found.
E           Expected: mock('', bar=4)
E           Actual: mock('fo')

/usr/lib64/python3.8/unittest/mock.py:2186: AssertionError

During handling of the above exception, another exception occurred:

__wrapped_mock_method__ = <function AsyncMockMixin.assert_awaited_once_with at 0x7f759b517430>
args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True
msg = "expected await not found.\nExpected: mock('', bar=4)\nActual: mock('fo')\n\npytest introspection follows:\n\nArgs:\n\nKwargs:\n"

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:403:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <AsyncMock id='140136262204192'>, args = ('',), kwargs = {'bar': 4}

    def assert_awaited_once_with(self, /, *args, **kwargs):
        """
        Assert that the mock was awaited exactly once and with the specified
        arguments.
        """
        if not self.await_count == 1:
            msg = (f"Expected {self._mock_name or 'mock'} to have been awaited once."
                   f" Awaited {self.await_count} times.")
            raise AssertionError(msg)
>       return self.assert_awaited_with(*args, **kwargs)

/usr/lib64/python3.8/unittest/mock.py:2197:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True

    def wrap_assert_awaited_with(*args: Any, **kwargs: Any) -> None:
        __tracebackhide__ = True
>       assert_wrapper(_mock_module_originals["assert_awaited_with"], *args, **kwargs)

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:471:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

__wrapped_mock_method__ = <function AsyncMockMixin.assert_awaited_with at 0x7f759b5173a0>
args = (<AsyncMock id='140136262204192'>, ''), kwargs = {'bar': 4}
__tracebackhide__ = True
msg = "expected await not found.\nExpected: mock('', bar=4)\nActual: mock('fo')\n\npytest introspection follows:\n\nArgs:\n\nKwargs:\n"
__mock_self = <AsyncMock id='140136262204192'>, actual_args = ('fo',)
actual_kwargs = {}, introspection = '\nArgs:\n\nKwargs:\n'

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
            __wrapped_mock_method__(*args, **kwargs)
            return
        except AssertionError as e:
            if getattr(e, "_mock_introspection_applied", 0):
                msg = str(e)
            else:
                __mock_self = args[0]
                msg = str(e)
                if __mock_self.call_args is not None:
                    actual_args, actual_kwargs = __mock_self.call_args
                    introspection = ""
                    try:
                        assert actual_args == args[1:]
                    except AssertionError as e_args:
                        introspection += "\nArgs:\n" + str(e_args)
                    try:
                        assert actual_kwargs == kwargs
                    except AssertionError as e_kwargs:
                        introspection += "\nKwargs:\n" + str(e_kwargs)
                    if introspection:
                        msg += "\n\npytest introspection follows:\n" + introspection
            e = AssertionError(msg)
            e._mock_introspection_applied = True  # type:ignore[attr-defined]
>           raise e
E           AssertionError: expected await not found.
E           Expected: mock('', bar=4)
E           Actual: mock('fo')
E
E           pytest introspection follows:
E
E           Args:
E
E           Kwargs:

/home/tkloczko/rpmbuild/BUILDROOT/python-pytest-mock-3.6.0-2.fc35.x86_64/usr/lib/python3.8/site-packages/pytest_mock/plugin.py:426: AssertionError

During handling of the above exception, another exception occurred:

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f740420fa30>

    @pytest.mark.asyncio
    async def test(mocker):
        m = mocker.AsyncMock()
        await m('fo')
>       m.assert_awaited_once_with('', bar=4)
E       AssertionError: expected await not found.
E       Expected: mock('', bar=4)
E       Actual: mock('fo')
E
E       pytest introspection follows:
E
E       Args:
E
E       Kwargs:

test_detailed_introspection_async.py:7: AssertionError
=========================== short test summary info ============================
FAILED test_detailed_introspection_async.py::test - AssertionError: expected ...
============================== 1 failed in 0.19s ===============================
========================================================================= short test summary info ==========================================================================
FAILED tests/test_pytest_mock.py::test_assert_called_args_with_introspection - assert 'Use -v to get the full diff' in "expected call not found.\nExpected: mock('b', 2, ...
FAILED tests/test_pytest_mock.py::test_assert_called_kwargs_with_introspection - assert 'Use -v to get the full diff' in "expected call not found.\nExpected: mock(foo={'...
FAILED tests/test_pytest_mock.py::test_standalone_mock - assert <ExitCode.OK: 0> == 3
FAILED tests/test_pytest_mock.py::test_detailed_introspection - Failed: nomatch: '*AssertionError: expected call not found.'
FAILED tests/test_pytest_mock.py::test_detailed_introspection_async - Failed: nomatch: '*AssertionError: expected await not found.'
====================================================================== 5 failed, 67 passed in 25.28s =======================================================================

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Apterykscommented, Aug 26, 2021

Hi again,

mock from the PyPI package is indeed available:

$ ./pre-inst-env guix graph --path python-pytest-mock python-mock
/gnu/packages/python-xyz.go
python-pytest-mock@3.6.1
python-pytest@5.3.5
python-mock@3.0.5

Propagated from pytest itself. I don’t believe that to be necessary anymore, but since touching pytest on Guix would entail rebuilding 7444 packages, I’ll have to leave it the way it is for now (I’ll skip the test).

Thanks for the help!

0reactions
nicoddemuscommented, Aug 26, 2021

test_standalone_mock is testing the mock_use_standalone_module option, which forces pytest-mock to use mock (from PyPI) instead of the builtin unittest.mock.

It expects that to fail with No module named 'mock' because in our own test environment mock is not installed, however it seems to be passing in your environment, I suppose because mock is installed there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3.6.4.0: pytest is failing · Issue #339 · celery/billiard - GitHub
I'm trying to package your module as an rpm package. So I'm using the typical build, install and test cycle used on building...
Read more >
Changelog — pytest documentation
After 6.2.0, these types began failing, because they inherited neither from standard Python number hierarchy nor from numpy.ndarray .
Read more >
pytest-cov - PyPI
Pytest plugin for measuring coverage. ... –cov-fail-under no longer causes pytest –collect-only to fail Contributed by Zac Hatfield-Dodds in #511.
Read more >
Contributing to the code base - Pandas
If the failing test has flaky behavior, use the argument strict=False . This will make it so pytest does not fail if the...
Read more >
Lesson 16: Pytest and practicing TDD
def test_number_negatives_for_invalid_amino_acid(): with pytest.raises(RuntimeError) as excinfo: > seq_features.number_negatives('Z') E Failed: DID NOT ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found