Skip to content

Commit 93b7ae3

Browse files
authored
Do not show "pytest introspection" msg when there is no introspe… (#162)
Do not show "pytest introspection" msg when there is no introspection
2 parents 4c3b469 + d971e76 commit 93b7ae3

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

CHANGELOG.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
1.11.1
2-
------
1+
1.11.2 (unreleased)
2+
-------------------
3+
4+
* The *pytest introspection follows* message is no longer shown
5+
if there is no pytest introspection (`#154`_).
6+
Thanks `@The-Compiler`_ for the report.
7+
8+
.. _#154: https://github.com/pytest-dev/pytest-mock/issues/154
9+
10+
1.11.1 (2019-10-04)
11+
-------------------
312

413
* Fix ``mocker.spy`` on Python 2 when used on non-function objects
514
which implement ``__call__`` (`#157`_). Thanks `@pbasista`_ for

src/pytest_mock/plugin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,18 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
212212
msg = text_type(e)
213213
if __mock_self.call_args is not None:
214214
actual_args, actual_kwargs = __mock_self.call_args
215-
msg += "\n\npytest introspection follows:\n"
215+
introspection = ""
216216
try:
217217
assert actual_args == args[1:]
218218
except AssertionError as e:
219-
msg += "\nArgs:\n" + text_type(e)
219+
introspection += "\nArgs:\n" + text_type(e)
220220
try:
221221
assert actual_kwargs == kwargs
222222
except AssertionError as e:
223-
msg += "\nKwargs:\n" + text_type(e)
223+
introspection += "\nKwargs:\n" + text_type(e)
224+
225+
if introspection:
226+
msg += "\n\npytest introspection follows:\n" + introspection
224227
e = AssertionError(msg)
225228
e._mock_introspection_applied = True
226229
raise e

tests/test_pytest_mock.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,20 @@ def test(mocker):
679679
result.stdout.fnmatch_lines(expected_lines)
680680

681681

682+
def test_missing_introspection(testdir):
683+
testdir.makepyfile(
684+
"""
685+
def test_foo(mocker):
686+
mock = mocker.Mock()
687+
mock('foo')
688+
mock('test')
689+
mock.assert_called_once_with('test')
690+
"""
691+
)
692+
result = testdir.runpytest()
693+
assert "pytest introspection follows:" not in result.stdout.str()
694+
695+
682696
def test_assert_called_with_unicode_arguments(mocker):
683697
"""Test bug in assert_call_with called with non-ascii unicode string (#91)"""
684698
stub = mocker.stub()

0 commit comments

Comments
 (0)