pytest: Assertion rewriting fails under Python 3.10.0a7+

Traceback (most recent call last):
  ...
  File "_pytest/assertion/rewrite.py", line 161, in exec_module
    source_stat, co = _rewrite_test(fn, self.config)
  File "_pytest/assertion/rewrite.py", line 356, in _rewrite_test
    co = compile(tree, fn_, "exec", dont_inherit=True)
TypeError: required field "lineno" missing from alias
full traceback
Traceback (most recent call last):
  File "/home/runner/.cache/hypothesis-build-runtimes/python-versions/3.10-dev/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/runner/.cache/hypothesis-build-runtimes/python-versions/3.10-dev/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/pytest/__main__.py", line 5, in <module>
    raise SystemExit(pytest.console_main())
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1168, in _preparse
    self.pluginmanager.consider_preparse(args, exclude_only=False)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 635, in consider_preparse
    self.consider_pluginarg(parg)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 660, in consider_pluginarg
    self.import_plugin(arg, consider_entry_points=True)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 713, in import_plugin
    self.register(mod, modname)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 443, in register
    self.consider_module(plugin)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 669, in consider_module
    self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 676, in _import_plugin_specs
    self.import_plugin(import_spec)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/config/__init__.py", line 703, in import_plugin
    __import__(importspec)
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 161, in exec_module
    source_stat, co = _rewrite_test(fn, self.config)
  File "/home/runner/work/hypothesis/hypothesis/hypothesis-python/.tox/py310-full/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 356, in _rewrite_test
    co = compile(tree, fn_, "exec", dont_inherit=True)
TypeError: required field "lineno" missing from alias

I discovered this in the Hypothesis CI, with Pytest 6.2.3 on Ubuntu and python3.10-dev (alpha07) from pyenv. Unfortunately I don’t have a smaller reproducing example than that, since my only copy of alpha07 is on that CI server.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

upgrade to 6.2.4 to get the fix!

Good news, the GitHub Actions weirdness has been resolved and latest pytest is working with 3.10-dev (example build from today). 🎈

What happened:

Something caused a premature Python-3.10.0b1.tgz to be released on the Python FTP servers (now removed): https://www.python.org/ftp/python/3.10.0/Python-3.10.0b1.tgz.

GitHub Actions’ automation integrated this into 3.10-dev. This has also been removed and 3.10-dev now points to the latest 3.10 alpha, in advance of next week’s real 3.10 beta release.

More details:

Due to the GitHub Actions weirdness (https://github.com/pytest-dev/pytest/pull/8540#issuecomment-822330273), is there a plan to release pytest with a fix before the real 3.10 beta (due 2021-05-03), or do you recommend we pin 3.10 to an alpha on GHA? Thank you!

I’ve renamed the issue a bit to be less confusing.

as first enhancement assertion rewrite should raise a ImportError that tells the file at least

I’m still experiencing this issue in Python 3.10.4 and pytest 7.1.2

It’s great that Actions has fixed their end of this (🎉), but unless we release a new version of pytest with #8540 soon we’ll be broken again when the real 3.10beta1 is released 😅

I’m OK with a prerelease, but we actually haven’t nailed down if the next release will be 7.0 or 6.3. We have a discussion about this: https://github.com/orgs/pytest-dev/teams/contributors/discussions/2

beta1 is out. can we please get (at least a pre-release) with this fix out?