Comparing called arguments with assert_called_with fails with UnicodeEncodeError when one of the arguments (either on the left or right) is a unicode string, non ascii.
Python 2.7.13
Below are two test cases that looks like they should work:
def test_assert_called_with_unicode_wrong_argument(mocker):
stub = mocker.stub()
stub('l\xc3\xb6k'.decode('UTF-8'))
with pytest.raises(AssertionError):
stub.assert_called_with(u'lak')
def test_assert_called_with_unicode_correct_argument(mocker):
stub = mocker.stub()
stub('l\xc3\xb6k'.decode('UTF-8'))
stub.assert_called_with('l\xc3\xb6k'.decode('UTF-8'))
Result:
test_pytest_mock.py::test_assert_called_with_unicode_wrong_argument FAILED
test_pytest_mock.py::test_assert_called_with_unicode_correct_argument PASSED
==== FAILURES ====
______test_assert_called_with_unicode_wrong_argument _______
mocker = <pytest_mock.MockFixture object at 0x104868f90>
def test_assert_called_with_unicode_wrong_argument(mocker):
stub = mocker.stub()
stub('l\xc3\xb6k'.decode('UTF-8'))
with pytest.raises(AssertionError):
> stub.assert_called_with(u'lak')
E UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 10: ordinal not in range(128)
test_pytest_mock.py:544: UnicodeEncodeError
Truncated traceback:
> pytest-mock/test_pytest_mock.py(544)test_assert_called_with_unicode_wrong_argument()
-> stub.assert_called_with(u'lak')
pytest-mock/pytest_mock.py(211)wrap_assert_called_with()
-> *args, **kwargs)
pytest-mock/pytest_mock.py(192)assert_wrapper()
-> msg += '\nArgs:\n' + str(e)
Comparing called arguments with
assert_called_withfails withUnicodeEncodeErrorwhen one of the arguments (either on the left or right) is a unicode string, non ascii.Python 2.7.13
Below are two test cases that looks like they should work:
Result:
Truncated traceback: