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

'ascii' codec can't encode characters - repr_locals #4618

Closed
gaborbernat opened this issue Jan 8, 2019 · 5 comments
Closed

'ascii' codec can't encode characters - repr_locals #4618

gaborbernat opened this issue Jan 8, 2019 · 5 comments

Comments

@gaborbernat
Copy link
Contributor

https://toxdev.visualstudio.com/tox/_build/results?buildId=1087

2019-01-08T18:37:09.2820943Z [gw1] [ 28%] PASSED tests/unit/test_config.py::TestConfigTestEnv::test_default_factors_conflict_ignore 
2019-01-08T18:37:12.3101907Z tests/unit/test_config.py::TestConfigTestEnv::test_default_factors_conflict INTERNALERROR> Traceback (most recent call last):
2019-01-08T18:37:12.3103870Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\main.py", line 184, in wrap_session
2019-01-08T18:37:12.3104246Z INTERNALERROR>     session.exitstatus = doit(config, session) or 0
2019-01-08T18:37:12.3104499Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\main.py", line 224, in _main
2019-01-08T18:37:12.3104709Z INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
2019-01-08T18:37:12.3104931Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\hooks.py", line 284, in __call__
2019-01-08T18:37:12.3105131Z INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
2019-01-08T18:37:12.3105375Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
2019-01-08T18:37:12.3105578Z INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
2019-01-08T18:37:12.3105796Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
2019-01-08T18:37:12.3106015Z INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
2019-01-08T18:37:12.3106238Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 208, in _multicall
2019-01-08T18:37:12.3106431Z INTERNALERROR>     return outcome.get_result()
2019-01-08T18:37:12.3106807Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 81, in get_result
2019-01-08T18:37:12.3106974Z INTERNALERROR>     _reraise(*ex)  # noqa
2019-01-08T18:37:12.3107315Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 187, in _multicall
2019-01-08T18:37:12.3107489Z INTERNALERROR>     res = hook_impl.function(*args)
2019-01-08T18:37:12.3107664Z INTERNALERROR>   File "<remote exec>", line 66, in pytest_runtestloop
2019-01-08T18:37:12.3107823Z INTERNALERROR>   File "<remote exec>", line 83, in run_one_test
2019-01-08T18:37:12.3107987Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\hooks.py", line 284, in __call__
2019-01-08T18:37:12.3108933Z INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
2019-01-08T18:37:12.3109102Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
2019-01-08T18:37:12.3109277Z INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
2019-01-08T18:37:12.3109457Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
2019-01-08T18:37:12.3109638Z INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
2019-01-08T18:37:12.3109962Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 208, in _multicall
2019-01-08T18:37:12.3110285Z INTERNALERROR>     return outcome.get_result()
2019-01-08T18:37:12.3110444Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 81, in get_result
2019-01-08T18:37:12.3110610Z INTERNALERROR>     _reraise(*ex)  # noqa
2019-01-08T18:37:12.3110779Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 187, in _multicall
2019-01-08T18:37:12.3110949Z INTERNALERROR>     res = hook_impl.function(*args)
2019-01-08T18:37:12.3111107Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\runner.py", line 77, in pytest_runtest_protocol
2019-01-08T18:37:12.3111299Z INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
2019-01-08T18:37:12.3111464Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\runner.py", line 92, in runtestprotocol
2019-01-08T18:37:12.3111622Z INTERNALERROR>     reports.append(call_and_report(item, "call", log))
2019-01-08T18:37:12.3111995Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\runner.py", line 174, in call_and_report
2019-01-08T18:37:12.3112161Z INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
2019-01-08T18:37:12.3112575Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\hooks.py", line 284, in __call__
2019-01-08T18:37:12.3113197Z INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
2019-01-08T18:37:12.3113429Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
2019-01-08T18:37:12.3113727Z INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
2019-01-08T18:37:12.3113955Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
2019-01-08T18:37:12.3114158Z INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
2019-01-08T18:37:12.3114399Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 203, in _multicall
2019-01-08T18:37:12.3114590Z INTERNALERROR>     gen.send(outcome)
2019-01-08T18:37:12.3114806Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\skipping.py", line 127, in pytest_runtest_makereport
2019-01-08T18:37:12.3115023Z INTERNALERROR>     rep = outcome.get_result()
2019-01-08T18:37:12.3115239Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 81, in get_result
2019-01-08T18:37:12.3115431Z INTERNALERROR>     _reraise(*ex)  # noqa
2019-01-08T18:37:12.3115859Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 187, in _multicall
2019-01-08T18:37:12.3116089Z INTERNALERROR>     res = hook_impl.function(*args)
2019-01-08T18:37:12.3116453Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\runner.py", line 251, in pytest_runtest_makereport
2019-01-08T18:37:12.3117427Z INTERNALERROR>     longrepr = item.repr_failure(excinfo)
2019-01-08T18:37:12.3117614Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\python.py", line 739, in repr_failure
2019-01-08T18:37:12.3117794Z INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
2019-01-08T18:37:12.3117951Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\nodes.py", line 393, in _repr_failure_py
2019-01-08T18:37:12.3118274Z INTERNALERROR>     truncate_locals=truncate_locals,
2019-01-08T18:37:12.3118433Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\_code\code.py", line 513, in getrepr
2019-01-08T18:37:12.3118602Z INTERNALERROR>     return fmt.repr_excinfo(self)
2019-01-08T18:37:12.3118756Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\_code\code.py", line 749, in repr_excinfo
2019-01-08T18:37:12.3118926Z INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
2019-01-08T18:37:12.3119086Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\_code\code.py", line 706, in repr_traceback
2019-01-08T18:37:12.3119363Z INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
2019-01-08T18:37:12.3119548Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\_code\code.py", line 676, in repr_traceback_entry
2019-01-08T18:37:12.3119731Z INTERNALERROR>     localsrepr = self.repr_locals(entry.locals)
2019-01-08T18:37:12.3119927Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\_code\code.py", line 638, in repr_locals
2019-01-08T18:37:12.3120079Z INTERNALERROR>     str_repr = pprint.pformat(value)
2019-01-08T18:37:12.3120246Z INTERNALERROR>   File "C:\hostedtoolcache\windows\Python\2.7.14\x64\Lib\pprint.py", line 63, in pformat
2019-01-08T18:37:12.3120405Z INTERNALERROR>     return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
2019-01-08T18:37:12.3120577Z INTERNALERROR>   File "C:\hostedtoolcache\windows\Python\2.7.14\x64\Lib\pprint.py", line 122, in pformat
2019-01-08T18:37:12.3120741Z INTERNALERROR>     self._format(object, sio, 0, 0, {}, 0)
2019-01-08T18:37:12.3120912Z INTERNALERROR>   File "C:\hostedtoolcache\windows\Python\2.7.14\x64\Lib\pprint.py", line 140, in _format
2019-01-08T18:37:12.3121063Z INTERNALERROR>     rep = self._repr(object, context, level - 1)
2019-01-08T18:37:12.3121231Z INTERNALERROR>   File "C:\hostedtoolcache\windows\Python\2.7.14\x64\Lib\pprint.py", line 226, in _repr
2019-01-08T18:37:12.3121390Z INTERNALERROR>     self._depth, level)
2019-01-08T18:37:12.3121558Z INTERNALERROR>   File "C:\hostedtoolcache\windows\Python\2.7.14\x64\Lib\pprint.py", line 238, in format
2019-01-08T18:37:12.3121712Z INTERNALERROR>     return _safe_repr(object, context, maxlevels, level)
2019-01-08T18:37:12.3122064Z INTERNALERROR>   File "C:\hostedtoolcache\windows\Python\2.7.14\x64\Lib\pprint.py", line 323, in _safe_repr
2019-01-08T18:37:12.3122217Z INTERNALERROR>     rep = repr(object)
2019-01-08T18:37:12.3122576Z INTERNALERROR> UnicodeEncodeError: 'ascii' codec can't encode characters in position 175-177: ordinal not in range(128)
2019-01-08T18:37:13.4695937Z 
2019-01-08T18:37:13.4696704Z INTERNALERROR> Traceback (most recent call last):
2019-01-08T18:37:13.4696934Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\main.py", line 184, in wrap_session
2019-01-08T18:37:13.4697536Z INTERNALERROR>     session.exitstatus = doit(config, session) or 0
2019-01-08T18:37:13.4698132Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\_pytest\main.py", line 224, in _main
2019-01-08T18:37:13.4698323Z INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
2019-01-08T18:37:13.4699051Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\hooks.py", line 284, in __call__
2019-01-08T18:37:13.4699823Z INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
2019-01-08T18:37:13.4700920Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
2019-01-08T18:37:13.4702090Z INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
2019-01-08T18:37:13.4702903Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
2019-01-08T18:37:13.4704484Z INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
2019-01-08T18:37:13.4705042Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 203, in _multicall
2019-01-08T18:37:13.4706102Z INTERNALERROR>     gen.send(outcome)
2019-01-08T18:37:13.4706310Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 81, in get_result
2019-01-08T18:37:13.4707810Z INTERNALERROR>     _reraise(*ex)  # noqa
2019-01-08T18:37:13.4708259Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\pluggy\callers.py", line 187, in _multicall
2019-01-08T18:37:13.4708687Z INTERNALERROR>     res = hook_impl.function(*args)
2019-01-08T18:37:13.4709209Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\xdist\dsession.py", line 115, in pytest_runtestloop
2019-01-08T18:37:13.4709617Z INTERNALERROR>     self.loop_once()
2019-01-08T18:37:13.4709950Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\xdist\dsession.py", line 138, in loop_once
2019-01-08T18:37:13.4710163Z INTERNALERROR>     call(**kwargs)
2019-01-08T18:37:13.4710946Z INTERNALERROR>   File "d:\a\1\s\.tox\py27\lib\site-packages\xdist\dsession.py", line 180, in worker_workerfinished
2019-01-08T18:37:13.4711531Z INTERNALERROR>     assert not crashitem, (crashitem, node)
2019-01-08T18:37:13.4712256Z INTERNALERROR> AssertionError: ('tests/unit/session/test_parallel.py::test_parallel_error_report', <WorkerController gw0>)
2019-01-08T18:37:13.4712770Z INTERNALERROR> assert not 'tests/unit/session/test_parallel.py::test_parallel_error_report'
2019-01-08T18:37:28.3318051Z 
2019-01-08T18:37:28.3328456Z ============== 133 passed, 2 skipped, 1 error in 103.69 seconds ===============
2019-01-08T18:37:28.3676175Z ERROR: InvocationError for command 'D:\\a\\1\\s\\.tox\\py27\\Scripts\\pytest.EXE --cov=D:\\a\\1\\s\\.tox\\py27\\Lib\\site-packages/tox --cov-config=D:\\a\\1\\s/tox.ini --timeout=180 -n=auto --junitxml=D:\\a\\1\\s\\.tox/.test.py27.xml .' (exited with code 3)
2019-01-08T18:37:28.3676808Z ___________________________________ summary ___________________________________
2019-01-08T18:37:28.3677364Z ERROR:   py27: commands failed
2019-01-08T18:37:28.4809698Z ##[error]Cmd.exe exited with code '1'.
2019-01-08T18:37:28.5189311Z ##[section]Finishing: run tests

Seems that the repr_locals does not handles nicely when cannot convert locals to ascii. Should we here ignore errors and maybe prin a warning instead?

@RonnyPfannschmidt
Copy link
Member

on python2 any repr must be bytes, as per https://docs.python.org/2/reference/datamodel.html#object.__repr__

@gaborbernat
Copy link
Contributor Author

You're right, can/should we maybe just give a better error message? 🤔

@RonnyPfannschmidt
Copy link
Member

its not clear to me where and how to correctly handle this

@asottile
Copy link
Member

asottile commented Jan 8, 2019

I think this is a duplicate though I'm having trouble finding it -- also thought we fixed this too 😆

is it this one? #1693

@asottile
Copy link
Member

asottile commented Jun 2, 2020

hello, first off thank you for the issue!

python 2.x support has ended for pytest core.

we've decided in #7296 to close the python-2-specific issues to free up some space in our backlog. however, in accordance to our python 2.7 and 3.4 support community patches will still be accepted to the 4.6 series to fix bugs for python 2. (so if this issue is important to you and you have a patch to fix it, feel free to make a PR targeting the 4.6.x branch despite this ticket being closed).

@asottile asottile closed this as completed Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants