Skip to content

Issue with rewrite test on Python 3.11-beta2 #10010

@rossbar

Description

@rossbar

We recently started experiencing failures in CI jobs testing against the Python 3.11 betas. This appears to have started with the Python 3.11-beta2 released 05/31/22.

Reproducing example ported over from CI

$ pytest --durations=10 --pyargs networkx
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/bin/pytest", line 8, in <module>
    sys.exit(console_main())
             ^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
           ^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/config/__init__.py", line 145, in main
    config = _prepareconfig(args, plugins)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/config/__init__.py", line 324, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
    ^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/helpconfig.py", line 102, in pytest_cmdline_parse
    config: Config = outcome.get_result()
                     ^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1016, in pytest_cmdline_parse
    self.parse(args)
    ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1304, in parse
    self._preparse(args, addopts=addopts)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1187, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
             ^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/importlib/metadata/__init__.py", line 198, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 159, in exec_module
    source_stat, co = _rewrite_test(fn, self.config)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.0-beta.2/x64/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 361, in _rewrite_test
    co = compile(tree, strfn, "exec", dont_inherit=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: line 2-0 is not a valid range

Output of pip list:

Package            Version
------------------ -------------
attrs              21.4.0
certifi            2022.5.18.1
charset-normalizer 2.0.12
codecov            2.1.12
coverage           6.4
idna               3.3
iniconfig          1.1.1
networkx           2.8.3rc1.dev0
packaging          21.3
pip                22.1.2
pluggy             1.0.0
py                 1.11.0
pyparsing          3.0.9
pytest             7.1.2
pytest-cov         3.0.0
requests           2.27.1
setuptools         62.3.2
tomli              2.0.1
urllib3            1.26.9
wheel              0.37.1

Pytest & OS versions:

pytest==7.1.2, OS=ubuntu-22.04 (from github actions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions