Skip to content

Commit 4f77abc

Browse files
authored
Merge pull request #92 from nicoddemus/release-1.6.3
Release 1.6.3
2 parents c56ba70 + 7cb24ba commit 4f77abc

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ deploy:
2525
provider: pypi
2626
user: nicoddemus
2727
skip_upload_docs: true
28+
distributions: sdist bdist_wheel
2829
password:
2930
secure: OEWrbk09CZRrwFE6sBpRqQHu45zRu1S0Ly1ZeprkFCKxMd9tZOnrYM5qxCDQXxFHIvuyajuJ+qWTOgxUvurQMNsD6DbvJKTJ0R8upH1b1Q95KK8xiJFedhqBEUga5GrInK59oo0Sgblse2jtH5NnHXRUClSdT+iHdLY5sljCTRg=
3031
on:
3132
tags: true
32-
distributions: sdist bdist_wheel
3333
repo: pytest-dev/pytest-mock
3434
condition: $TRAVIS_PYTHON_VERSION = 3.6

CHANGELOG.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
1.6.3
2+
-----
3+
4+
* Fix ``UnicodeDecodeError`` during assert introspection in ``assert_called_with`` in Python 2.
5+
Thanks `@AndreasHogstrom`_ for the report (`#91`_).
6+
7+
8+
.. _@AndreasHogstrom: https://github.com/AndreasHogstrom
9+
10+
.. _#91: https://github.com/pytest-dev/pytest-mock/issues/91
11+
112
1.6.2
213
-----
314

pytest_mock.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import unicode_literals
2+
13
import inspect
24
import sys
35

@@ -7,6 +9,12 @@
79

810
__version__ = version
911

12+
# pseudo-six; if this starts to require more than this, depend on six already
13+
if sys.version_info[0] == 2: # pragma: no cover
14+
text_type = unicode # noqa
15+
else:
16+
text_type = str
17+
1018

1119
def _get_mock_module(config):
1220
"""
@@ -179,21 +187,21 @@ def assert_wrapper(__wrapped_mock_method__, *args, **kwargs):
179187
return
180188
except AssertionError as e:
181189
if getattr(e, '_mock_introspection_applied', 0):
182-
msg = str(e)
190+
msg = text_type(e)
183191
else:
184192
__mock_self = args[0]
185-
msg = str(e)
193+
msg = text_type(e)
186194
if __mock_self.call_args is not None:
187195
actual_args, actual_kwargs = __mock_self.call_args
188196
msg += '\n\npytest introspection follows:\n'
189197
try:
190198
assert actual_args == args[1:]
191199
except AssertionError as e:
192-
msg += '\nArgs:\n' + str(e)
200+
msg += '\nArgs:\n' + text_type(e)
193201
try:
194202
assert actual_kwargs == kwargs
195203
except AssertionError as e:
196-
msg += '\nKwargs:\n' + str(e)
204+
msg += '\nKwargs:\n' + text_type(e)
197205
e = AssertionError(msg)
198206
e._mock_introspection_applied = True
199207
raise e

test_pytest_mock.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,13 @@ def test(mocker):
534534
"*{'bar': 4}*",
535535
"*Use -v to get the full diff*",
536536
])
537+
538+
539+
def test_assert_called_with_unicode_arguments(mocker):
540+
"""Test bug in assert_call_with called with non-ascii unicode string (#91)"""
541+
stub = mocker.stub()
542+
stub(b'l\xc3\xb6k'.decode('UTF-8'))
543+
544+
with pytest.raises(AssertionError):
545+
stub.assert_called_with(u'lak')
546+

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ commands =
1313
coverage run --append --source=pytest_mock.py -m pytest test_pytest_mock.py
1414

1515
[testenv:linting]
16-
basepython = python3.5
1716
skip_install=True
1817
deps =
1918
pytest-flakes

0 commit comments

Comments
 (0)