-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 393: invalid continuation byte" from codecs.py #12895
Comments
Same issue on pytest-django File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "D:\Projects\Trade_IT\.venv\Scripts\pytest.exe\__main__.py", line 7, in <module>
sys.exit(console_main())
~~~~~~~~~~~~^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\__init__.py", line 201, in console_main
code = main()
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\__init__.py", line 156, in main
config = _prepareconfig(args, plugins)
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\__init__.py", line 341, in _prepareconfig
config = pluginmanager.hook.pytest_cmdline_parse(
pluginmanager=pluginmanager, args=args
)
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\helpconfig.py", line 105, in pytest_cmdline_parse
config = yield
^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\__init__.py", line 1140, in pytest_cmdline_parse
self.parse(args)
~~~~~~~~~~^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\__init__.py", line 1494, in parse
self._preparse(args, addopts=addopts)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\__init__.py", line 1366, in _preparse
self._initini(args)
~~~~~~~~~~~~~^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\__init__.py", line 1239, in _initini
rootpath, inipath, inicfg = determine_setup(
~~~~~~~~~~~~~~~^
inifile=ns.inifilename,
^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
invocation_dir=self.invocation_params.dir,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\findpaths.py", line 198, in determine_setup
rootdir, inipath, inicfg = locate_config(invocation_dir, [ancestor])
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\findpaths.py", line 110, in locate_config
ini_config = load_config_dict_from_file(p)
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\findpaths.py", line 39, in load_config_dict_from_file
iniconfig = _parse_ini_config(filepath)
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\_pytest\config\findpaths.py", line 25, in _parse_ini_config
return iniconfig.IniConfig(str(path))
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "D:\Projects\Trade_IT\.venv\Lib\site-packages\iniconfig\__init__.py", line 118, in __init__
data = fp.read()
File "<frozen codecs>", line 325, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte |
We used |
Without a reproducing example, unfortunately we're unlikely to be able to help. |
Issue was due to current working directory. I had to move back to previous one. |
Unfortunately I can't help much, without some sample code that I can run to see the same problem (and then run again to confirm that a fix makes the problem stop). https://stackoverflow.com/help/minimal-reproducible-example explains the idea style. I suspect that this is because you have a file which is not in utf-8 encoding - that wouldn't be pytest's fault but we might be able to improve the error message. |
No, encoding was fine. Case is that I have to run pytest from outside django project directory. |
Telling me that does not help; I need sample code that I can execute to see the problem for myself. |
Sorry, my english is not good. I solved the problem, this is solution: "I have to run pytest from outside django project directory.". Now is everything alright. |
Thank you so much for trying to help me! |
I removed --log-level and it is working fine now.
My pytest script calls another script via So, in the following error message:
It seems pytest tries to capture the whole source code, but My observation might be incorrect but just in case leave it as it is for now. |
It looks like we might have a pytest issue when trying to construct a custom traceback repr involving source lines from a file which is not utf-8 encoded. |
I tried to reproduce the issue with simple codes but couldn't do that... In case of someone reporting the smilar issue, I will keep this open. |
Okay, I am coming back with answer. My IDE is vscode but saving there with encoding 'utf-8', wasn't working. Finally I tried same method with sublime text and everything is alright. |
Test environment
We use pytest v8.0.2 with Python 3.9.13 environment on Ubuntu 18.04 Docker image.
Here is a part of metadata from pytest output:
platform linux -- Python 3.9.13, pytest-8.0.2, pluggy-1.5.0 -- /home/autouser/venv/bin/python metadata: {'Python': '3.9.13', 'Platform': 'Linux-3.10.0-957.21.3.el7.x86_64-x86_64-with-glibc2.27', 'Packages': {'pytest': '8.0.2', 'pluggy': '1.5.0'}, 'Plugins': {'variables': '3.1.0', 'forked': '1.6.0', 'timeout': '2.3.1', 'parallel': '0.1.1', 'json-report': '1.5.0', 'json': '0.4.0', 'metadata': '3.1.1', 'xdist': '1.24.1', 'html': '4.1.1', 'bdd': '7.2.0', 'ordering': '0.6', 'instafail': '0.4.1'}
Here is the output from
pip list
:Test pytest command
We run the testcases with the following command:
pytest --skip-library-install --instafail -rs --tb=short -m "xxxx" --timeout 86400 --disable-pytest-warnings --log-level INFO
Issue
During testing, pytest issues INTERNALERROR as follows:
We have no idea which part of our test cases caused this issue. We are wondering if this is a bug from pytest?
The text was updated successfully, but these errors were encountered: