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

Decode error in pytest.ini with chinese characters #5

Closed
nicoddemus opened this issue Aug 10, 2018 · 4 comments
Closed

Decode error in pytest.ini with chinese characters #5

nicoddemus opened this issue Aug 10, 2018 · 4 comments

Comments

@nicoddemus
Copy link
Member

Reported originally in pytest-dev/pytest#3799 by @edsion1107

@edsion1107 a PR here (with accompanying test) would be welcome!


  • pytest 3.7.1

pytest.ini:

[pytest]
log_file = pytest.log
log_file_level = INFO
log_file_format = %(asctime)s %(module)s.%(funcName)s %(levelname)s %(message)s
log_cli=true
log_cli_level = WARNING
log_cli_format = %(msecs)d %(filename)s(%(lineno)d) %(levelname)s %(message)s
# 中文
;--basetemp=../results
;--tap-files
;--html=report.html --self-contained-html

I have tried to add Chinese comment ,then this error occurs:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.2.1\helpers\pycharm\_jb_pytest_runner.py", line 31, in <module>
    pytest.main(args, plugins_to_load)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\__init__.py", line 55, in main
    config = _prepareconfig(args, plugins)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\__init__.py", line 180, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\pluggy\hooks.py", line 258, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
    firstresult=hook.spec_opts.get('firstresult'),
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\pluggy\callers.py", line 196, in _multicall
    gen.send(outcome)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\pluggy\callers.py", line 76, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\pluggy\callers.py", line 180, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\__init__.py", line 612, in pytest_cmdline_parse
    self.parse(args)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\__init__.py", line 777, in parse
    self._preparse(args, addopts=addopts)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\__init__.py", line 723, in _preparse
    self._initini(args)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\__init__.py", line 666, in _initini
    rootdir_cmd_arg=ns.rootdir or None,
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\findpaths.py", line 118, in determine_setup
    rootdir, inifile, inicfg = getcfg([ancestor], warnfunc=warnfunc)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\_pytest\config\findpaths.py", line 35, in getcfg
    iniconfig = py.iniconfig.IniConfig(p)
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\py\_vendored_packages\iniconfig.py", line 55, in __init__
    tokens = self._parse(iter(f))
  File "C:\Users\p_jbzhang\.virtualenvs\wecar-tMZRsXDh\lib\site-packages\py\_vendored_packages\iniconfig.py", line 83, in _parse
    for lineno, line in enumerate(line_iter):
UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 259: illegal multibyte sequence

I tried to fix this error:

# filename: iniconfig.py
# line: 49
class IniConfig(object):
    def __init__(self, path, data=None):
        self.path = str(path)  # convenience
        if data is None:
            # f = open(self.path)     
            # add encoding params 
            f = open(self.path, encoding='utf-8')
            try:
                tokens = self._parse(iter(f))
            finally:
                f.close()
        else:
            tokens = self._parse(data.splitlines(True))
@RonnyPfannschmidt
Copy link
Member

currently iniconfog is NOT unicode aware ^^ see #4

Jehops pushed a commit to Jehops/freebsd-ports-legacy that referenced this issue May 18, 2019
This package supports Python 3.x support, so allow it accordingly. It is
required for an upcoming www/py-autobahn update (Python 2/3 compatible).

During QA, a UnicodeDecodeError was observed running tests under Python 3:

File "/usr/local/lib/python3.6/site-packages/py/_vendored_packages/iniconfig.py", line 82, in _parse
  for lineno, line in enumerate(line_iter):
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 165: ordinal not in range(128)

pytest uses the py package, which vendors the iniconfig package, which
isn't unicode aware [1][2][3]. Patch out unicode characters from setup.cfg
accordingly until it's resolved.

While investigating the cause of the above issue, a fix for setup.cfg's
encoding was identified, which removes the need to set the locale via
USE_LOCALE so remove it accordingly.

While I'm here:

  - Pet portlint, spurious space at end of line in pkg-descr
  - Add LICENSE_FILE/TEST_DEPENDS/test target/NO_ARCH

[1] pytest-dev/pytest#3799
[2] pytest-dev/iniconfig#5
[3] pytest-dev/iniconfig#4

portlint: OK (looks fine.)
porttest: OK (poudriere: 12amd64{py36,py27})
maketest: 215 passed, 1 skipped in 3.29 seconds (Python 2.7)
maketest: 209 passed, 7 skipped in 3.07 seconds (Python 3.6)

Approved by:	portmgr (blanket: ports/framework compliance)
MFH:		2019Q2


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@501964 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue May 18, 2019
This package supports Python 3.x support, so allow it accordingly. It is
required for an upcoming www/py-autobahn update (Python 2/3 compatible).

During QA, a UnicodeDecodeError was observed running tests under Python 3:

File "/usr/local/lib/python3.6/site-packages/py/_vendored_packages/iniconfig.py", line 82, in _parse
  for lineno, line in enumerate(line_iter):
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 165: ordinal not in range(128)

pytest uses the py package, which vendors the iniconfig package, which
isn't unicode aware [1][2][3]. Patch out unicode characters from setup.cfg
accordingly until it's resolved.

While investigating the cause of the above issue, a fix for setup.cfg's
encoding was identified, which removes the need to set the locale via
USE_LOCALE so remove it accordingly.

While I'm here:

  - Pet portlint, spurious space at end of line in pkg-descr
  - Add LICENSE_FILE/TEST_DEPENDS/test target/NO_ARCH

[1] pytest-dev/pytest#3799
[2] pytest-dev/iniconfig#5
[3] pytest-dev/iniconfig#4

portlint: OK (looks fine.)
porttest: OK (poudriere: 12amd64{py36,py27})
maketest: 215 passed, 1 skipped in 3.29 seconds (Python 2.7)
maketest: 209 passed, 7 skipped in 3.07 seconds (Python 3.6)

Approved by:	portmgr (blanket: ports/framework compliance)
MFH:		2019Q2


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@501964 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue May 18, 2019
This package supports Python 3.x support, so allow it accordingly. It is
required for an upcoming www/py-autobahn update (Python 2/3 compatible).

During QA, a UnicodeDecodeError was observed running tests under Python 3:

File "/usr/local/lib/python3.6/site-packages/py/_vendored_packages/iniconfig.py", line 82, in _parse
  for lineno, line in enumerate(line_iter):
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 165: ordinal not in range(128)

pytest uses the py package, which vendors the iniconfig package, which
isn't unicode aware [1][2][3]. Patch out unicode characters from setup.cfg
accordingly until it's resolved.

While investigating the cause of the above issue, a fix for setup.cfg's
encoding was identified, which removes the need to set the locale via
USE_LOCALE so remove it accordingly.

While I'm here:

  - Pet portlint, spurious space at end of line in pkg-descr
  - Add LICENSE_FILE/TEST_DEPENDS/test target/NO_ARCH

[1] pytest-dev/pytest#3799
[2] pytest-dev/iniconfig#5
[3] pytest-dev/iniconfig#4

portlint: OK (looks fine.)
porttest: OK (poudriere: 12amd64{py36,py27})
maketest: 215 passed, 1 skipped in 3.29 seconds (Python 2.7)
maketest: 209 passed, 7 skipped in 3.07 seconds (Python 3.6)

Approved by:	portmgr (blanket: ports/framework compliance)
MFH:		2019Q2
swills pushed a commit to swills/freebsd-ports that referenced this issue May 22, 2019
This package supports Python 3.x support, so allow it accordingly. It is
required for an upcoming www/py-autobahn update (Python 2/3 compatible).

During QA, a UnicodeDecodeError was observed running tests under Python 3:

File "/usr/local/lib/python3.6/site-packages/py/_vendored_packages/iniconfig.py", line 82, in _parse
  for lineno, line in enumerate(line_iter):
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 165: ordinal not in range(128)

pytest uses the py package, which vendors the iniconfig package, which
isn't unicode aware [1][2][3]. Patch out unicode characters from setup.cfg
accordingly until it's resolved.

While investigating the cause of the above issue, a fix for setup.cfg's
encoding was identified, which removes the need to set the locale via
USE_LOCALE so remove it accordingly.

While I'm here:

  - Pet portlint, spurious space at end of line in pkg-descr
  - Add LICENSE_FILE/TEST_DEPENDS/test target/NO_ARCH

[1] pytest-dev/pytest#3799
[2] pytest-dev/iniconfig#5
[3] pytest-dev/iniconfig#4

portlint: OK (looks fine.)
porttest: OK (poudriere: 12amd64{py36,py27})
maketest: 215 passed, 1 skipped in 3.29 seconds (Python 2.7)
maketest: 209 passed, 7 skipped in 3.07 seconds (Python 3.6)

Approved by:	portmgr (blanket: ports/framework compliance)
MFH:		2019Q2


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@501964 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this issue May 24, 2019
This package supports Python 3.x support, so allow it accordingly. It is
required for an upcoming www/py-autobahn update (Python 2/3 compatible).

During QA, a UnicodeDecodeError was observed running tests under Python 3:

File "/usr/local/lib/python3.6/site-packages/py/_vendored_packages/iniconfig.py", line 82, in _parse
  for lineno, line in enumerate(line_iter):
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 165: ordinal not in range(128)

pytest uses the py package, which vendors the iniconfig package, which
isn't unicode aware [1][2][3]. Patch out unicode characters from setup.cfg
accordingly until it's resolved.

While investigating the cause of the above issue, a fix for setup.cfg's
encoding was identified, which removes the need to set the locale via
USE_LOCALE so remove it accordingly.

While I'm here:

  - Pet portlint, spurious space at end of line in pkg-descr
  - Add LICENSE_FILE/TEST_DEPENDS/test target/NO_ARCH

[1] pytest-dev/pytest#3799
[2] pytest-dev/iniconfig#5
[3] pytest-dev/iniconfig#4

portlint: OK (looks fine.)
porttest: OK (poudriere: 12amd64{py36,py27})
maketest: 215 passed, 1 skipped in 3.29 seconds (Python 2.7)
maketest: 209 passed, 7 skipped in 3.07 seconds (Python 3.6)

Approved by:	portmgr (blanket: ports/framework compliance)

Approved by:	ports-secteam (joneum, blanket: ports/framework compliance)
@RonnyPfannschmidt
Copy link
Member

now that pytest 5 is out i believe we can support unicode markers in some sense and default to utf8 or BOM detection

uqs pushed a commit to freebsd/freebsd-ports that referenced this issue Apr 1, 2021
This package supports Python 3.x support, so allow it accordingly. It is
required for an upcoming www/py-autobahn update (Python 2/3 compatible).

During QA, a UnicodeDecodeError was observed running tests under Python 3:

File "/usr/local/lib/python3.6/site-packages/py/_vendored_packages/iniconfig.py", line 82, in _parse
  for lineno, line in enumerate(line_iter):
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 165: ordinal not in range(128)

pytest uses the py package, which vendors the iniconfig package, which
isn't unicode aware [1][2][3]. Patch out unicode characters from setup.cfg
accordingly until it's resolved.

While investigating the cause of the above issue, a fix for setup.cfg's
encoding was identified, which removes the need to set the locale via
USE_LOCALE so remove it accordingly.

While I'm here:

  - Pet portlint, spurious space at end of line in pkg-descr
  - Add LICENSE_FILE/TEST_DEPENDS/test target/NO_ARCH

[1] pytest-dev/pytest#3799
[2] pytest-dev/iniconfig#5
[3] pytest-dev/iniconfig#4

portlint: OK (looks fine.)
porttest: OK (poudriere: 12amd64{py36,py27})
maketest: 215 passed, 1 skipped in 3.29 seconds (Python 2.7)
maketest: 209 passed, 7 skipped in 3.07 seconds (Python 3.6)

Approved by:	portmgr (blanket: ports/framework compliance)

Approved by:	ports-secteam (joneum, blanket: ports/framework compliance)
@RobertT93
Copy link

i tried proposed fix locally and it seams to work f = open(self.path, encoding='utf-8')

@RonnyPfannschmidt
Copy link
Member

closing as likely solved by #49

svmhdvn pushed a commit to svmhdvn/freebsd-ports that referenced this issue Jan 10, 2024
This package supports Python 3.x support, so allow it accordingly. It is
required for an upcoming www/py-autobahn update (Python 2/3 compatible).

During QA, a UnicodeDecodeError was observed running tests under Python 3:

File "/usr/local/lib/python3.6/site-packages/py/_vendored_packages/iniconfig.py", line 82, in _parse
  for lineno, line in enumerate(line_iter):
File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
  return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 165: ordinal not in range(128)

pytest uses the py package, which vendors the iniconfig package, which
isn't unicode aware [1][2][3]. Patch out unicode characters from setup.cfg
accordingly until it's resolved.

While investigating the cause of the above issue, a fix for setup.cfg's
encoding was identified, which removes the need to set the locale via
USE_LOCALE so remove it accordingly.

While I'm here:

  - Pet portlint, spurious space at end of line in pkg-descr
  - Add LICENSE_FILE/TEST_DEPENDS/test target/NO_ARCH

[1] pytest-dev/pytest#3799
[2] pytest-dev/iniconfig#5
[3] pytest-dev/iniconfig#4

portlint: OK (looks fine.)
porttest: OK (poudriere: 12amd64{py36,py27})
maketest: 215 passed, 1 skipped in 3.29 seconds (Python 2.7)
maketest: 209 passed, 7 skipped in 3.07 seconds (Python 3.6)

Approved by:	portmgr (blanket: ports/framework compliance)
MFH:		2019Q2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants