Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError in detailed introspection of assert_called_with #91

Closed
AndreasHogstrom opened this issue Sep 15, 2017 · 2 comments
Closed
Labels

Comments

@AndreasHogstrom
Copy link

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)
@nicoddemus
Copy link
Member

Thanks for the report!

@nicoddemus
Copy link
Member

Released in 1.6.3, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants