-
-
Notifications
You must be signed in to change notification settings - Fork 150
Closed
Description
pytest-mock version 3.15.0
TEST LOGS:
=================================== FAILURES ===================================
__________________ test_assert_called_args_with_introspection __________________
self = <MagicMock spec='function' id='140126685703584'>
args = ('b', 2, {'jest'}), kwargs = {}
expected = call('', ('b', 2, {'jest'}), {})
actual = call('', ('a', 1, {'test'}), {})
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f71c977f1c0>
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(_Call((args, kwargs), two=True))
actual = self._call_matcher(self.call_args)
if actual != expected:
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'})
../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/unittest/mock.py:929: AssertionError
During handling of the above exception, another exception occurred:
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f71c958af20>
@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)
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:
E assert ('a', 1, {'test'}) == ('b', 2, {'jest'})
E
E At index 0 diff: 'a' != 'b'
E
E Full diff:
E (
E - 'b',
E ? ^
E + 'a',
E ? ^
E - 2,
E ? ^
E + 1,
E ? ^
E {
E - 'jest',
E ? ^
E + 'test',
E ? ^
E },
E )
tests/test_pytest_mock.py:713: AssertionError
During handling of the above exception, another exception occurred:
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f71c958af20>
@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):
tests/test_pytest_mock.py:712:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/contextlib.py:153: in __exit__
self.gen.throw(typ, value, traceback)
tests/test_pytest_mock.py:646: in assert_argument_introspection
util._compare_eq_iterable(left, right, lambda t, *_: t, verbose)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
left = ('a', 1, {'test'}), right = ('b', 2, {'jest'})
highlighter = <function assert_argument_introspection.<locals>.<lambda> at 0x7f71c977f130>
verbose = True
def _compare_eq_iterable(
left: Iterable[Any],
right: Iterable[Any],
highlighter: _HighlightFunc,
verbose: int = 0,
) -> list[str]:
if verbose <= 0 and not running_on_ci():
return ["Use -v to get more diff"]
# dynamic import to speedup pytest
import difflib
left_formatting = PrettyPrinter().pformat(left).splitlines()
right_formatting = PrettyPrinter().pformat(right).splitlines()
explanation = ["", "Full diff:"]
# "right" is the expected base against which we compare "left",
# see https://github.com/pytest-dev/pytest/issues/3333
explanation.extend(
> highlighter(
"\n".join(
line.rstrip()
for line in difflib.ndiff(right_formatting, left_formatting)
),
lexer="diff",
).splitlines()
)
E TypeError: assert_argument_introspection.<locals>.<lambda>() got an unexpected keyword argument 'lexer'
../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/site-packages/_pytest/assertion/util.py:358: TypeError
_________________ test_assert_called_kwargs_with_introspection _________________
self = <MagicMock spec='function' id='140126680824080'>, args = ()
kwargs = {'foo': {'baz': 'bran', 'goo': 1}}
expected = call('', (), {'foo': {'goo': 1, 'baz': 'bran'}})
actual = call('', (), {'foo': {'bar': 1, 'baz': 'spam'}})
_error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x7f71c95c5b40>
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(_Call((args, kwargs), two=True))
actual = self._call_matcher(self.call_args)
if actual != expected:
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'})
../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/unittest/mock.py:929: AssertionError
During handling of the above exception, another exception occurred:
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f71c908bd30>
@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)
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:
E assert {'foo': {'bar': 1, 'baz': 'spam'}} == {'foo': {'goo': 1, 'baz': 'bran'}}
E
E Differing items:
E {'foo': {'bar': 1, 'baz': 'spam'}} != {'foo': {'baz': 'bran', 'goo': 1}}
E
E Full diff:
E {
E 'foo': {
E + 'bar': 1,
E - 'baz': 'bran',
E ? ^^ ^
E + 'baz': 'spam',
E ? ^^ ^
E - 'goo': 1,
E },
E }
tests/test_pytest_mock.py:729: AssertionError
During handling of the above exception, another exception occurred:
mocker = <pytest_mock.plugin.MockerFixture object at 0x7f71c908bd30>
@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):
tests/test_pytest_mock.py:728:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/contextlib.py:153: in __exit__
self.gen.throw(typ, value, traceback)
tests/test_pytest_mock.py:646: in assert_argument_introspection
util._compare_eq_iterable(left, right, lambda t, *_: t, verbose)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
left = {'foo': {'bar': 1, 'baz': 'spam'}}
right = {'foo': {'baz': 'bran', 'goo': 1}}
highlighter = <function assert_argument_introspection.<locals>.<lambda> at 0x7f71c95c7e20>
verbose = True
def _compare_eq_iterable(
left: Iterable[Any],
right: Iterable[Any],
highlighter: _HighlightFunc,
verbose: int = 0,
) -> list[str]:
if verbose <= 0 and not running_on_ci():
return ["Use -v to get more diff"]
# dynamic import to speedup pytest
import difflib
left_formatting = PrettyPrinter().pformat(left).splitlines()
right_formatting = PrettyPrinter().pformat(right).splitlines()
explanation = ["", "Full diff:"]
# "right" is the expected base against which we compare "left",
# see https://github.com/pytest-dev/pytest/issues/3333
explanation.extend(
> highlighter(
"\n".join(
line.rstrip()
for line in difflib.ndiff(right_formatting, left_formatting)
),
lexer="diff",
).splitlines()
)
E TypeError: assert_argument_introspection.<locals>.<lambda>() got an unexpected keyword argument 'lexer'
../_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/site-packages/_pytest/assertion/util.py:358: TypeError
=============================== warnings summary ===============================
tests/test_pytest_mock.py::test_detailed_introspection
tests/test_pytest_mock.py::test_detailed_introspection_async
tests/test_pytest_mock.py::test_missing_introspection
tests/test_pytest_mock.py::test_abort_patch_context_manager_with_stale_pyc
tests/test_pytest_mock.py::test_abort_patch_context_manager_with_stale_pyc
/home/task_175768662335982/conda-bld/pytest-mock_1757686679877/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_/lib/python3.10/site-packages/pytest_asyncio/plugin.py:208: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"
warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_pytest_mock.py::test_assert_called_args_with_introspection - TypeError: assert_argument_introspection.<locals>.<lambda>() got an unexpected keyword argument 'lexer'
FAILED tests/test_pytest_mock.py::test_assert_called_kwargs_with_introspection - TypeError: assert_argument_introspection.<locals>.<lambda>() got an unexpected keyword argument 'lexer'
============= 2 failed, 85 passed, 1 skipped, 5 warnings in 2.23s ==============
TEST ENVIRONMENT:
defaults/linux-64::expat-2.7.1-h6a678d5_0
defaults/linux-64::xorg-libxau-1.0.12-h9b100fa_0
defaults/linux-64::sqlite-3.50.2-hb25bd0a_1
defaults/linux-64::readline-8.3-hc2a1206_0
defaults/linux-64::libgomp-11.2.0-h1234567_1
defaults/linux-64::xz-5.6.4-h5eee18b_1
defaults/linux-64::_libgcc_mutex-0.1-main
file:///home/task_175768662335982/test_dir/linux-64::pytest-mock-3.15.0-py310h06a4308_1
defaults/linux-64::openssl-3.0.17-h5eee18b_0
defaults/linux-64::_openmp_mutex-5.1-1_gnu
defaults/linux-64::pluggy-1.5.0-py310h06a4308_0
defaults/linux-64::libxcb-1.17.0-h9b100fa_0
defaults/linux-64::packaging-25.0-py310h06a4308_0
defaults/linux-64::pygments-2.19.1-py310h06a4308_0
defaults/linux-64::libzlib-1.3.1-hb25bd0a_0
defaults/linux-64::ca-certificates-2025.9.9-h06a4308_0
defaults/linux-64::setuptools-78.1.1-py310h06a4308_0
defaults/linux-64::ncurses-6.5-h7934f7d_0
defaults/linux-64::xorg-xorgproto-2024.1-h5eee18b_1
defaults/linux-64::python-3.10.18-h1a3bd86_0
defaults/linux-64::xorg-libxdmcp-1.1.5-h9b100fa_0
defaults/linux-64::libuuid-1.41.5-h5eee18b_0
defaults/linux-64::exceptiongroup-1.2.0-py310h06a4308_0
defaults/linux-64::tomli-2.2.1-py310h06a4308_0
defaults/noarch::tzdata-2025b-h04d1e81_0
defaults/linux-64::bzip2-1.0.8-h5eee18b_6
defaults/linux-64::pthread-stubs-0.3-h0ce48e5_1
defaults/linux-64::pytest-asyncio-1.0.0-py310h06a4308_0
defaults/linux-64::libffi-3.4.4-h6a678d5_1
defaults/linux-64::xorg-libx11-1.8.12-h9b100fa_1
defaults/linux-64::iniconfig-2.1.0-py310h06a4308_0
defaults/linux-64::zlib-1.3.1-hb25bd0a_0
defaults/linux-64::libstdcxx-ng-11.2.0-h1234567_1
defaults/linux-64::libgcc-ng-11.2.0-h1234567_1
defaults/linux-64::wheel-0.45.1-py310h06a4308_0
defaults/noarch::pip-25.2-pyhc872135_0
defaults/linux-64::tk-8.6.15-h54e0aa7_0
defaults/linux-64::pytest-8.4.1-py310h06a4308_0
defaults/linux-64::ld_impl_linux-64-2.40-h12ee557_0
The lexer has been added only in pytest 8.0.0
Metadata
Metadata
Assignees
Labels
No labels