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

3.11.0b1 ValueError "not a valid range" #10008

Closed
AA-Turner opened this issue May 31, 2022 · 8 comments
Closed

3.11.0b1 ValueError "not a valid range" #10008

AA-Turner opened this issue May 31, 2022 · 8 comments

Comments

@AA-Turner
Copy link
Contributor

AA-Turner commented May 31, 2022

Sphinx's CI failed on a PR to fix a typo, but only on 3.11.0b1 with a mysterious error:

ImportError while loading conftest '/home/runner/work/sphinx/sphinx/tests/conftest.py'.
ValueError: line 1-0 is not a valid range

CI link (sorry, I tried to install 3.11.0b1 on windows for a smaller reproducer but my computer disagreed) https://github.com/sphinx-doc/sphinx/runs/6669825488?check_suite_focus=true

Packages distlib-0.3.4 filelock-3.7.0 packaging-21.3 platformdirs-2.5.2 pluggy-1.0.0 py-1.11.0 pyparsing-3.0.9 six-1.16.0 toml-0.10.2 tox-3.25.0 virtualenv-20.14.1 alabaster==0.7.12,attrs==21.4.0,Babel==2.10.1,certifi==2022.5.18.1,charset-normalizer==2.0.12,Cython==0.29.30,docutils==0.18.1,html5lib==1.1,idna==3.3,imagesize==1.3.0,iniconfig==1.1.1,Jinja2==3.1.2,MarkupSafe==2.1.1,packaging==21.3,pluggy==1.0.0,py==1.11.0,Pygments==2.12.0,pyparsing==3.0.9,pytest==7.1.2,pytz==2022.1,requests==2.27.1,six==1.16.0,snowballstemmer==2.2.0,sphinxcontrib-applehelp==1.0.2,sphinxcontrib-devhelp==1.0.2,sphinxcontrib-htmlhelp==2.0.0,sphinxcontrib-jsmath==1.0.1,sphinxcontrib-qthelp==1.0.3,sphinxcontrib-serializinghtml==1.1.5,tomli==2.0.1,urllib3==1.26.9,webencodings==0.5.1

pytest 7.1.2; ubuntu 18.04.6

My guess is this is an issue with pytest (or 3.11.0b1?) as it failed whilst loading conftest, and nothing changed beyond two typos. I searched for "not a valid range" but didn't find any prior issues.

A

@The-Compiler
Copy link
Member

Possibly related: python/cpython#92597

(end_lineno is set to 0 instead of a saner value in the AST of Python 3.11)

@nedbat
Copy link
Contributor

nedbat commented May 31, 2022

Also related: python/cpython#93387

@hroncok
Copy link
Member

hroncok commented May 31, 2022

Test failures of pytest itself:

$ tox -e py311
py311 inst-nodeps: .../pytest/.tox/.tmp/package/1/pytest-7.2.0.dev138+g130c954bb.tar.gz
py311 installed: argcomplete==2.0.0,attrs==21.4.0,certifi==2022.5.18.1,charset-normalizer==2.0.12,elementpath==2.5.3,hypothesis==6.46.9,idna==3.3,iniconfig==1.1.1,mock==4.0.3,nose==1.3.7,packaging==21.3,pluggy==1.0.0,py==1.11.0,Pygments==2.12.0,pyparsing==3.0.9,pytest @ file://.../pytest/.tox/.tmp/package/1/pytest-7.2.0.dev138%2Bg130c954bb.tar.gz,requests==2.27.1,sortedcontainers==2.4.0,urllib3==1.26.9,xmlschema==1.11.1
py311 run-test-pre: PYTHONHASHSEED='3950729182'
py311 run-test: commands[0] | pytest
Traceback (most recent call last):
  File ".../pytest/.tox/py311/bin/pytest", line 8, in <module>
    sys.exit(console_main())
             ^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 188, in console_main
    code = main()
           ^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 146, in main
    config = _prepareconfig(args, plugins)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 327, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
    ^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
    config: Config = outcome.get_result()
                     ^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1032, in pytest_cmdline_parse
    self.parse(args)
    ^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1320, in parse
    self._preparse(args, addopts=addopts)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1199, in _preparse
    self.pluginmanager.consider_preparse(args, exclude_only=False)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 677, in consider_preparse
    self.consider_pluginarg(parg)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 703, in consider_pluginarg
    self.import_plugin(arg, consider_entry_points=True)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 759, in import_plugin
    self.register(mod, modname)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 473, in register
    self.consider_module(plugin)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 715, in consider_module
    self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 722, in _import_plugin_specs
    self.import_plugin(import_spec)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/config/__init__.py", line 749, in import_plugin
    __import__(importspec)
    ^^^^^^^^^^^^^^^^^^^^^^
  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 ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 159, in exec_module
    source_stat, co = _rewrite_test(fn, self.config)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pytest/.tox/py311/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 361, in _rewrite_test
    co = compile(tree, strfn, "exec", dont_inherit=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: line 6-0 is not a valid range
ERROR: InvocationError for command .../pytest/.tox/py311/bin/pytest (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py311: commands failed

@nedbat
Copy link
Contributor

nedbat commented May 31, 2022

This is fixed by python/cpython#93359 most likely.

@jeanas
Copy link

jeanas commented May 31, 2022

As helpfully pointed out by @pablogsal on python-dev (https://mail.python.org/archives/list/python-dev@python.org/thread/VZ222BFFAWW73DYFCR7NZR2C5M3TXD65/), you can work around this issue by invoking pytest with --assert=plain.

@hroncok
Copy link
Member

hroncok commented Jun 1, 2022

This is fixed by python/cpython#93359 most likely.

I can confirm that this is indeed fixed by that commit.

@nicoddemus
Copy link
Member

Thanks @hroncok!

I suppose we can close this then?

jarrodmillman added a commit to jarrodmillman/numpydoc that referenced this issue Jun 2, 2022
Temporary workaround for pytest failures on 3.11b2. See pytest-dev/pytest#10008 and the [Python 3.11b2 release notes](https://www.python.org/downloads/release/python-3110b2/) for more info.
jarrodmillman added a commit to numpy/numpydoc that referenced this issue Jun 2, 2022
Temporary workaround for pytest failures on 3.11b2. See pytest-dev/pytest#10008 and the [Python 3.11b2 release notes](https://www.python.org/downloads/release/python-3110b2/) for more info.
@chmp
Copy link

chmp commented Apr 20, 2023

Since I'm using the private pytest API, I only have to myself to blame, but just an FYI: the missing end_lineno values are creating issues when running pytest inside notebooks using ipytest (maintained by me).

As a fix I will set the end_lineno of the top-level import statements (see here). The reason why the issue persists in IPython is, that IPython explicitly calls ast.fix_missing_locations which creates an invalid line range (see here).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants