-
-
Notifications
You must be signed in to change notification settings - Fork 149
Closed
Labels
Description
Hello I have tried to run the tests. But some was failed:
> + /usr/bin/python3 -m pytest
> ============================= test session starts ==============================
> platform linux -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
> rootdir: /builddir/build/BUILD/pytest-mock-1.11.2, inifile: tox.ini
> plugins: mock-1.11.2, cov-2.7.1, hypothesis-3.12.0
> collected 53 items
>
> tests/test_pytest_mock.py ......................................FF...... [ 86%]
> .FF.... [100%]
>
> =================================== FAILURES ===================================
> __________________ test_assert_called_args_with_introspection __________________
>
> left = ('a', 1, {'test'}), right = ('b', 2, {'jest'})
>
> @contextmanager
> def assert_argument_introspection(left, right):
> """
> Assert detailed argument introspection is used
> """
> try:
> > yield
>
> tests/test_pytest_mock.py:410:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> mocker = <pytest_mock.plugin.MockFixture object at 0x7f597696eb00>
>
> @pytest.mark.usefixtures("needs_assert_rewrite")
> def test_assert_called_args_with_introspection(mocker):
> stub = mocker.stub()
>
> complex_args = ("a", 1, set(["test"]))
> wrong_args = ("b", 2, set(["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:488:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> args = (<MagicMock spec='function' id='140022218418496'>, 'b', 2, {'jest'})
> kwargs = {}, __tracebackhide__ = True
>
> def wrap_assert_called_with(*args, **kwargs):
> __tracebackhide__ = True
> > assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs)
>
> ../../BUILDROOT/python-pytest-mock-1.11.2-1.el7.x86_64/usr/lib/python3.6/site-packages/pytest_mock/plugin.py:253:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> __wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f5977652ea0>
> args = (<MagicMock spec='function' id='140022218418496'>, 'b', 2, {'jest'})
> kwargs = {}, __tracebackhide__ = True
> e = AssertionError("Expected call: mock('b', 2, {'jest'})\nActual call: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n",)
> msg = "Expected call: mock('b', 2, {'jest'})\nActual call: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n"
> __mock_self = <MagicMock spec='function' id='140022218418496'>
> actual_args = ('a', 1, {'test'}), actual_kwargs = {}
> introspection = '\nArgs:\n'
>
> def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
> __tracebackhide__ = True
> try:
> __wrapped_mock_method__(*args, **kwargs)
> return
> except AssertionError as e:
> if getattr(e, "_mock_introspection_applied", 0):
> msg = text_type(e)
> else:
> __mock_self = args[0]
> msg = text_type(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:
> introspection += "\nArgs:\n" + text_type(e)
> try:
> assert actual_kwargs == kwargs
> except AssertionError as e:
> introspection += "\nKwargs:\n" + text_type(e)
>
> if introspection:
> msg += "\n\npytest introspection follows:\n" + introspection
> e = AssertionError(msg)
> e._mock_introspection_applied = True
> > raise e
> E AssertionError: Expected call: mock('b', 2, {'jest'})
> E Actual call: mock('a', 1, {'test'})
> E
> E pytest introspection follows:
> E
> E Args:
>
> ../../BUILDROOT/python-pytest-mock-1.11.2-1.el7.x86_64/usr/lib/python3.6/site-packages/pytest_mock/plugin.py:243: AssertionError
>
> During handling of the above exception, another exception occurred:
>
> mocker = <pytest_mock.plugin.MockFixture object at 0x7f597696eb00>
>
> @pytest.mark.usefixtures("needs_assert_rewrite")
> def test_assert_called_args_with_introspection(mocker):
> stub = mocker.stub()
>
> complex_args = ("a", 1, set(["test"]))
> wrong_args = ("b", 2, set(["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:489:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> /usr/lib64/python3.6/contextlib.py:99: in __exit__
> self.gen.throw(type, value, traceback)
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> left = ('a', 1, {'test'}), right = ('b', 2, {'jest'})
>
> @contextmanager
> def assert_argument_introspection(left, right):
> """
> 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: mock('b', 2, {'jest'})\nActual call: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n"
> E + where "Expected call: mock('b', 2, {'jest'})\nActual call: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n" = str(AssertionError("Expected call: mock('b', 2, {'jest'})\nActual call: mock('a', 1, {'test'})\n\npytest introspection follows:\n\nArgs:\n",))
>
> tests/test_pytest_mock.py:419: AssertionError
> _________________ test_assert_called_kwargs_with_introspection _________________
>
> left = {'foo': {'bar': 1, 'baz': 'spam'}}
> right = {'foo': {'baz': 'bran', 'goo': 1}}
>
> @contextmanager
> def assert_argument_introspection(left, right):
> """
> Assert detailed argument introspection is used
> """
> try:
> > yield
>
> tests/test_pytest_mock.py:410:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> mocker = <pytest_mock.plugin.MockFixture object at 0x7f59769592e8>
>
> @pytest.mark.usefixtures("needs_assert_rewrite")
> def test_assert_called_kwargs_with_introspection(mocker):
> 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:504:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> args = (<MagicMock spec='function' id='140022218331584'>,)
> kwargs = {'foo': {'baz': 'bran', 'goo': 1}}, __tracebackhide__ = True
>
> def wrap_assert_called_with(*args, **kwargs):
> __tracebackhide__ = True
> > assert_wrapper(_mock_module_originals["assert_called_with"], *args, **kwargs)
>
> ../../BUILDROOT/python-pytest-mock-1.11.2-1.el7.x86_64/usr/lib/python3.6/site-packages/pytest_mock/plugin.py:253:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> __wrapped_mock_method__ = <function NonCallableMock.assert_called_with at 0x7f5977652ea0>
> args = (<MagicMock spec='function' id='140022218331584'>,)
> kwargs = {'foo': {'baz': 'bran', 'goo': 1}}, __tracebackhide__ = True
> e = AssertionError("Expected call: mock(foo={'goo': 1, 'baz': 'bran'})\nActual call: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n",)
> msg = "Expected call: mock(foo={'goo': 1, 'baz': 'bran'})\nActual call: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n"
> __mock_self = <MagicMock spec='function' id='140022218331584'>, actual_args = ()
> actual_kwargs = {'foo': {'bar': 1, 'baz': 'spam'}}
> introspection = '\nKwargs:\n'
>
> def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
> __tracebackhide__ = True
> try:
> __wrapped_mock_method__(*args, **kwargs)
> return
> except AssertionError as e:
> if getattr(e, "_mock_introspection_applied", 0):
> msg = text_type(e)
> else:
> __mock_self = args[0]
> msg = text_type(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:
> introspection += "\nArgs:\n" + text_type(e)
> try:
> assert actual_kwargs == kwargs
> except AssertionError as e:
> introspection += "\nKwargs:\n" + text_type(e)
>
> if introspection:
> msg += "\n\npytest introspection follows:\n" + introspection
> e = AssertionError(msg)
> e._mock_introspection_applied = True
> > raise e
> E AssertionError: Expected call: mock(foo={'goo': 1, 'baz': 'bran'})
> E Actual call: mock(foo={'bar': 1, 'baz': 'spam'})
> E
> E pytest introspection follows:
> E
> E Kwargs:
>
> ../../BUILDROOT/python-pytest-mock-1.11.2-1.el7.x86_64/usr/lib/python3.6/site-packages/pytest_mock/plugin.py:243: AssertionError
>
> During handling of the above exception, another exception occurred:
>
> mocker = <pytest_mock.plugin.MockFixture object at 0x7f59769592e8>
>
> @pytest.mark.usefixtures("needs_assert_rewrite")
> def test_assert_called_kwargs_with_introspection(mocker):
> 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:505:
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> /usr/lib64/python3.6/contextlib.py:99: 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, right):
> """
> 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: mock(foo={'goo': 1, 'baz': 'bran'})\nActual call: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n"
> E + where "Expected call: mock(foo={'goo': 1, 'baz': 'bran'})\nActual call: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n" = str(AssertionError("Expected call: mock(foo={'goo': 1, 'baz': 'bran'})\nActual call: mock(foo={'bar': 1, 'baz': 'spam'})\n\npytest introspection follows:\n\nKwargs:\n",))
>
> tests/test_pytest_mock.py:419: AssertionError
> _____________________________ test_standalone_mock _____________________________
>
> testdir = <Testdir local('/tmp/pytest-of-mockbuild/pytest-0/test_standalone_mock0')>
>
> @pytest.mark.skipif(sys.version_info[0] < 3, reason="Py3 only")
> def test_standalone_mock(testdir):
> """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 = runpytest_subprocess(testdir)
> > assert result.ret == 3
> E assert 0 == 3
> E + where 0 = <RunResult ret=0 len(stdout.lines)=9 len(stderr.lines)=0 duration=0.28s>.ret
>
> /builddir/build/BUILD/pytest-mock-1.11.2/tests/test_pytest_mock.py:630: AssertionError
> ----------------------------- Captured stdout call -----------------------------
> running: /usr/bin/python3 -mpytest --basetemp=/tmp/pytest-of-mockbuild/pytest-0/test_standalone_mock0/runpytest-0
> in: /tmp/pytest-of-mockbuild/pytest-0/test_standalone_mock0
> ============================= test session starts ==============================
> platform linux -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
> rootdir: /tmp/pytest-of-mockbuild/pytest-0/test_standalone_mock0, inifile: tox.ini
> plugins: mock-1.11.2, cov-2.7.1, hypothesis-3.12.0
> collected 1 item
>
> test_standalone_mock.py . [100%]
>
> =========================== 1 passed in 0.01 seconds ===========================
> _________________________ test_detailed_introspection __________________________
>
> testdir = <Testdir local('/tmp/pytest-of-mockbuild/pytest-0/test_detailed_introspection0')>
>
> @pytest.mark.usefixtures("needs_assert_rewrite")
> def test_detailed_introspection(testdir):
> """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: mock('', bar=4)*"
> E and: '============================= test session starts =============================='
> E and: 'platform linux -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0'
> E and: 'rootdir: /tmp/pytest-of-mockbuild/pytest-0/test_detailed_introspection0'
> E and: 'plugins: mock-1.11.2, cov-2.7.1, hypothesis-3.12.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: 'mocker = <pytest_mock.plugin.MockFixture object at 0x7f5976811160>'
> 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 fnmatch: "*AssertionError: Expected call: mock('', bar=4)*"
> E with: "E AssertionError: Expected call: mock('', bar=4)"
> E fnmatch: "*Actual call: mock('fo')*"
> E with: "E Actual call: mock('fo')"
> E nomatch: '*pytest introspection follows:*'
> E and: 'E '
> E fnmatch: '*pytest introspection follows:*'
> E with: 'E pytest introspection follows:'
> E nomatch: '*Args:'
> 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: 'test_detailed_introspection.py:4: AssertionError'
> E and: '=========================== 1 failed in 0.01 seconds ==========================='
> E and: ''
> E remains unmatched: "*assert ('fo',) == ('',)"
>
> /builddir/build/BUILD/pytest-mock-1.11.2/tests/test_pytest_mock.py:679: Failed
> ----------------------------- Captured stdout call -----------------------------
> ============================= test session starts ==============================
> platform linux -- Python 3.6.8, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
> rootdir: /tmp/pytest-of-mockbuild/pytest-0/test_detailed_introspection0
> plugins: mock-1.11.2, cov-2.7.1, hypothesis-3.12.0
> collected 1 item
>
> test_detailed_introspection.py F
>
> =================================== FAILURES ===================================
> _____________________________________ test _____________________________________
>
> mocker = <pytest_mock.plugin.MockFixture object at 0x7f5976811160>
>
> def test(mocker):
> m = mocker.Mock()
> m('fo')
> > m.assert_called_once_with('', bar=4)
> E AssertionError: Expected call: mock('', bar=4)
> E Actual call: mock('fo')
> E
> E pytest introspection follows:
> E
> E Args:
> E
> E Kwargs:
>
> test_detailed_introspection.py:4: AssertionError
> =========================== 1 failed in 0.01 seconds ===========================
> =========================== short test summary info ============================
> FAILED tests/test_pytest_mock.py::test_assert_called_args_with_introspection
> FAILED tests/test_pytest_mock.py::test_assert_called_kwargs_with_introspection
> FAILED tests/test_pytest_mock.py::test_standalone_mock - assert 0 == 3
> FAILED tests/test_pytest_mock.py::test_detailed_introspection - Failed: nomat...
> ===================== 4 failed, 49 passed in 1.68 seconds ======================