Skip to content

_pytest.doctest._is_setup_py raises with LC_ALL=C and UTF-8 chars in setup.py #7180

@arekfu

Description

@arekfu

pytest runs into an exception when collecting tests from a repository where setup.py contains UTF-8 characters, but the locale is set to C.

Minimal example: setup.py:

# -*- coding: utf-8 -*-

from setuptools import setup, find_packages,

name = 'mypkg'
author = u'Lóts of åccénts Ánd diàcritičs'
author_email = u'me@myjob.org'
copyright = u'2020, ' + author

setup(name=name,
      author=author,
      author_email=author_email,
      url=r'http://',
      packages=find_packages(exclude=['doc', 'tests', 'tests.*']),
      version='0.1',
      )

To reproduce:

$ export LC_ALL=C
$ pytest setup.py   # or just pytest
===================================================================================================================================================== test session starts =====================================================================================================================================================
platform linux -- Python 3.6.8, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- /***/bin/python3
cachedir: .pytest_cache
Matplotlib: 3.2.1
Freetype: 2.6.1
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/***/.hypothesis/examples')
rootdir: /***, inifile: setup.cfg
plugins: mpl-0.11, timeout-1.3.4, xdist-1.32.0, forked-1.1.3, hypothesis-5.10.5, cov-2.8.1
collected 0 items / 1 error

=========================================================================================================================================================== ERRORS ============================================================================================================================================================
________________________________________________________________________________________________________________________________________________ ERROR collecting test session ________________________________________________________________________________________________________________________________________________
/***/lib64/python3.6/site-packages/pluggy/hooks.py:286: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
/***/lib64/python3.6/site-packages/pluggy/manager.py:93: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
/***/lib64/python3.6/site-packages/pluggy/manager.py:87: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
/***/lib64/python3.6/site-packages/_pytest/doctest.py:114: in pytest_collect_file
    if config.option.doctestmodules and not _is_setup_py(config, path, parent):
/***/lib64/python3.6/site-packages/_pytest/doctest.py:123: in _is_setup_py
    contents = path.read()
/***/lib64/python3.6/site-packages/py/_path/common.py:177: in read
    return f.read()
/usr/lib64/python3.6/encodings/ascii.py:26: in decode
    return codecs.ascii_decode(input, self.errors)[0]
E   UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 98: ordinal not in range(128)
=================================================================================================================================================== short test summary info ===================================================================================================================================================
ERROR  - UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 98: ordinal not in range(128)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================================================================================================== 1 error in 0.44s =======================================================================================================================================================

Tested on CentOS 7.7.1908:

$ python3 --version
Python 3.6.8
$ pytest --version
This is pytest version 5.4.1, imported from /***/lib64/python3.6/site-packages/pytest/__init__.py                                                                                                                                                                                                   
setuptools registered plugins:                                                                                                                                                                                                                                                                                                 
  pytest-mpl-0.11 at /***/lib64/python3.6/site-packages/pytest_mpl/plugin.py                                                                                                                                                                                                                        
  pytest-timeout-1.3.4 at /***/lib64/python3.6/site-packages/pytest_timeout.py                                                                                                                                                                                                                      
  pytest-xdist-1.32.0 at /***/lib64/python3.6/site-packages/xdist/plugin.py                                                                                                                                                                                                                         
  pytest-xdist-1.32.0 at /***/lib64/python3.6/site-packages/xdist/looponfail.py                                                                                                                                                                                                                     
  pytest-forked-1.1.3 at /***/lib64/python3.6/site-packages/pytest_forked/__init__.py                                                                                                                                                                                                               
  hypothesis-5.10.5 at /***/lib64/python3.6/site-packages/hypothesis/extra/pytestplugin.py                                                                                                                                                                                                          
  pytest-cov-2.8.1 at /***/lib64/python3.6/site-packages/pytest_cov/plugin.py
$ pip list
Package                       Version               Location
----------------------------- --------------------- ----------------------------------
alabaster                     0.7.12
apipkg                        1.5
astroid                       2.4.1
attrs                         19.3.0
Babel                         2.8.0
backcall                      0.1.0
certifi                       2020.4.5.1
chardet                       3.0.4
coverage                      5.1
cycler                        0.10.0
decorator                     4.4.2
docutils                      0.16
entrypoints                   0.3
execnet                       1.7.1
flake8                        3.7.9
hypothesis                    5.10.5
idna                          2.9
imagesize                     1.2.0
importlib-metadata            1.6.0
ipython                       7.14.0
ipython-genutils              0.2.0
isort                         4.3.21
jedi                          0.17.0
Jinja2                        2.11.2
kiwisolver                    1.2.0
lazy-object-proxy             1.4.3
MarkupSafe                    1.1.1
matplotlib                    3.2.1
mccabe                        0.6.1
more-itertools                8.2.0
nose                          1.3.7
numpy                         1.18.4
packaging                     20.3
parso                         0.7.0
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        7.1.2
pip                           20.1
pluggy                        0.13.1
prompt-toolkit                3.0.5
ptyprocess                    0.6.0
py                            1.8.1
pycodestyle                   2.5.0
pydot                         1.4.1
pyflakes                      2.1.1
Pygments                      2.6.1
pylint                        2.5.2
pyparsing                     2.4.7
pytest                        5.4.1
pytest-cov                    2.8.1
pytest-forked                 1.1.3
pytest-mpl                    0.11
pytest-timeout                1.3.4
pytest-xdist                  1.32.0
python-dateutil               2.8.1
pytz                          2020.1
requests                      2.23.0
rstcheck                      3.3.1
scipy                         1.4.1
setuptools                    46.1.3
six                           1.14.0
snowballstemmer               2.0.0
sortedcontainers              2.1.0
Sphinx                        3.0.3
sphinx-rtd-theme              0.4.3
sphinxcontrib-applehelp       1.0.2
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        1.0.3
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.4
toml                          0.10.0
traitlets                     4.3.3
typed-ast                     1.4.1
urllib3                       1.25.9
wcwidth                       0.1.9
wrapt                         1.12.1
zipp                          3.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributorplugin: doctestsrelated to the doctests builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions