pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
12.02k stars 2.67k forks source link

PyTest has began to fail on Python3.8 #5838

Closed ghost closed 5 years ago

ghost commented 5 years ago

Since this morning, Pytest on 3.8 has been failing due to an issue passing a Context object to functions in the regex model.

I am making this report on mobile, so apologies if I miss anything. Traceback is as follows:

poetry run python -W ignore::DeprecationWarning -m pytest --cov hikari.core --cov-config .coveragerc --cov-report term --cov-report annotate:public/coverage/annotated --cov-report html:public/coverage/html --cov-branch -ra --showlocals --testdox tests/hikari/core
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/pytest.py", line 7, in <module>
    from _pytest.config import cmdline
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/_pytest/config/__init__.py", line 12, in <module>
    import importlib_metadata
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 527, in <module>
    __version__ = version(__name__)
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 494, in version
    return distribution(package).version
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 467, in distribution
    return Distribution.from_name(package)
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 181, in from_name
    dists = resolver(DistributionFinder.Context(name=name))
  File "<frozen importlib._bootstrap_external>", line 1385, in find_distributions
  File "/usr/local/lib/python3.8/re.py", line 275, in escape
    pattern = str(pattern, 'latin1')
TypeError: decoding to str: need a bytes-like object, Context found
Command poetry run python -W ignore::DeprecationWarning -m pytest --cov hikari.core --cov-config .coveragerc --cov-report term --cov-report annotate:public/coverage/annotated --cov-report html:public/coverage/html --cov-branch -ra --showlocals --testdox tests/hikari/core failed with exit code 1
Session pytest failed.

My "pip freeze" from Poetry:

$ poetry show -v
Using virtualenv: /root/.cache/pypoetry/virtualenvs/hikari.core-py3.8
aiohttp            3.5.4     Async http client/server framework (asyncio)
astroid            2.2.5     An abstract syntax tree for Python with infere...
async-timeout      3.0.1     Timeout context manager for asyncio programs
asynctest          0.13.0    Enhance the standard unittest package with fea...
atomicwrites       1.3.0     Atomic file writes.
attrs              19.1.0    Classes Without Boilerplate
chardet            3.0.4     Universal encoding detector for Python 2 and 3
colorlog           3.2.0     Log formatting with colors!
coverage           4.5.4     Code coverage measurement for Python
idna               2.8       Internationalized Domain Names in Applications...
importlib-metadata 0.21      Read metadata from Python packages
isort              4.3.21    A Python utility / library to sort Python impo...
lazy-object-proxy  1.4.2     A fast and thorough lazy object proxy.
mccabe             0.6.1     McCabe checker, plugin for flake8
more-itertools     7.2.0     More routines for operating on iterables, beyo...
multidict          4.5.2     multidict implementation
nox                2019.5.30 Flexible test automation.
packaging          19.1      Core utilities for Python packages
pluggy             0.13.0    plugin and hook calling mechanisms for python
py                 1.8.0     library with cross-python path, ini-parsing, i...
pylint             2.3.1     python code static checker
pyparsing          2.4.2     Python parsing module
pytest             5.0.1     pytest: simple powerful testing with Python
pytest-asyncio     0.10.0    Pytest support for asyncio.
pytest-cov         2.7.1     Pytest plugin for measuring coverage.
pytest-html        1.22.0    pytest plugin for generating HTML reports
pytest-metadata    1.8.0     pytest plugin for test session metadata
pytest-testdox     1.1.1     A testdox format reporter for pytest
six                1.12.0    Python 2 and 3 compatibility utilities
typed-ast          1.4.0     a fork of Python 2 and 3 ast modules with type...
virtualenv         16.7.5    Virtual Python Environment builder
wcwidth            0.1.7     Measures number of Terminal column cells of wi...
websockets         8.0.2     An implementation of the WebSocket Protocol (R...
wrapt              1.11.2    Module for decorators, wrappers and monkey pat...
yarl               1.3.0     Yet another URL library
zipp               0.6.0     Backport of pathlib-compatible object wrapper ...

The pipeline that triggered this is here, if you need more information or anything let me know and I will try to dig down into my CI configuration to find out:

https://gitlab.com/nekokatt/hikari.core/-/jobs/292464486

I can confirm on behalf of another user that they are getting the exact same error running Pytest on Python3.8-rc-alpine on their repository.

This bug is present on CPython3.8-rc and CPython3.8-b4, and is not present on CPython3.7.x, nor PyPy 3.6 (that I am aware of).

Hope this is all the info you need for now. Thanks :)

RonnyPfannschmidt commented 5 years ago

this is a known api breaking fixup change, updating importlib_metadata and pluggy should resolve it

blueyed commented 5 years ago

@RonnyPfannschmidt

importlib-metadata 0.21 pluggy 0.13.0

Those are the latest, no?

I was seeing this myself locally - but it was fixed eventually when cleaning the old Python 3.8 install, and re-installing it.

RonnyPfannschmidt commented 5 years ago

Argh true, so it's indeed look like a old python 3.8 build

blueyed commented 5 years ago

Ref: https://gitlab.com/python-devs/importlib_metadata/issues/86

@nekokatt

This bug is present on CPython3.8-rc and CPython3.8-b4

There is no RC yet, is there? Try with a clean install, i.e. remove the existing installation before "make install".

ghost commented 5 years ago

My mistake, misread the docker page.

These are prebuilt images that are provided on Docker hub, so without rerunning that from scratch, which would involve pulling my CI configuration apart to change it, I don't really have control over that. Those are pulled from docker hub and then I do a fresh install on each run of pytest + co

Is pluggy importlib_metadata updated to the newest version as per that release, do we know? Or has this been updated on PyPi already for Pytest?

Thanks for the quick reply


Edit, this is still an issue with the most recent pytest pullable from pypi, as the dependency list on a pipeline I just ran reflects.

Installing importlib-metadata (0.21)
...
Installing pluggy (0.13.0)
...
Installing pytest (5.0.1)
...
$ poetry run nox -spytest
Running session pytest
Creating virtualenv using python in .nox/pytest
pip install poetry
poetry update
Updating dependencies
Resolving dependencies...

Nothing to install or update

poetry run python -W ignore::DeprecationWarning -m pytest --cov hikari.core --cov-config .coveragerc --cov-report term --cov-report annotate:public/coverage/annotated --cov-report html:public/coverage/html --cov-branch -ra --showlocals --testdox tests/hikari/core
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 192, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/pytest.py", line 7, in <module>
    from _pytest.config import cmdline
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/_pytest/config/__init__.py", line 12, in <module>
    import importlib_metadata
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 527, in <module>
    __version__ = version(__name__)
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 494, in version
    return distribution(package).version
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 467, in distribution
    return Distribution.from_name(package)
  File "/root/.cache/pypoetry/virtualenvs/hikari.core-py3.8/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 181, in from_name
    dists = resolver(DistributionFinder.Context(name=name))
  File "<frozen importlib._bootstrap_external>", line 1385, in find_distributions
  File "/usr/local/lib/python3.8/re.py", line 275, in escape
    pattern = str(pattern, 'latin1')
TypeError: decoding to str: need a bytes-like object, Context found
Command poetry run python -W ignore::DeprecationWarning -m pytest --cov hikari.core --cov-config .coveragerc --cov-report term --cov-report annotate:public/coverage/annotated --cov-report html:public/coverage/html --cov-branch -ra --showlocals --testdox tests/hikari/core failed with exit code 1
Session pytest failed.

Is there a reason pytest is not using the recommended importlib mechanism that is suggested at the PR you linked?

ghost commented 5 years ago

Can confirm it is now working with a version bump. Cheers for responding so quickly; greatly appreciated :)