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

Fix assertion rewriting on Python 3.10 #8540

Merged
merged 3 commits into from
Apr 15, 2021

Conversation

hauntsaninja
Copy link
Contributor

Fixes #8539

This seems to have been the result of https://bugs.python.org/issue43798

@hauntsaninja
Copy link
Contributor Author

Hmm, looks like the test is failing on master as well. Looks like it's benjaminp/six#352

@@ -684,12 +684,9 @@ def run(self, mod: ast.Module) -> None:
if not mod.body:
# Nothing to do.
return

# Insert some special imports at the top of the module but after any
# docstrings and __future__ imports.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment has been orphaned

Copy link
Contributor Author

@hauntsaninja hauntsaninja Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment is still relevant in its current place! L690-L720 is figuring out the "after any docstrings and __future__ imports part".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's 40 lines away from the code that's relevant to the comment (the "special imports")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, made a change! :-)

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The-Compiler added a commit to The-Compiler/pytest that referenced this pull request Apr 14, 2021
It currently breaks all builds and even after pytest-dev#8540 it looks like tests
still fail because of benjaminp/six#341

As a hotfix, mark it as experimental until everything is fixed, so that
our CI isn't all red.
@The-Compiler
Copy link
Member

Could someone elaborate on how I can actually reproduce this? I'm trying to fix the testsuite on Python 3.10, but I don't see this issue happening at all.

@asottile
Copy link
Member

Could someone elaborate on how I can actually reproduce this? I'm trying to fix the testsuite on Python 3.10, but I don't see this issue happening at all.

for example: https://github.com/asottile/flake8-match

git clone [email protected]:asottile/flake8-match
sudo add-apt-repository ppa:deadsnakes/nightly
sudo apt install python3.10-dev
tox -e py310

@The-Compiler
Copy link
Member

Ah, I see - I was running 3.10.0a7 (because that's what @Zac-HD mentioned in the issue), but this is actually a very recent change. I can reproduce it when installing python3.10-dev via pyenv, which gives me "Python 3.10.0a7+ (heads/master:d9ba9de, Apr 14 2021, 16:49:31)".

This also explains why this isn't needed on CI - it will be once beta 1 is out.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @hauntsaninja!

@nicoddemus nicoddemus merged commit af31c60 into pytest-dev:main Apr 15, 2021
@nicoddemus
Copy link
Member

Should have squashed, my bad! 🤦‍♂️

@hroncok
Copy link
Member

hroncok commented Apr 15, 2021

Will this not break actual alpha 7?

@nicoddemus
Copy link
Member

Hmm I suppose, good point. Should we revert this and wait for beta 1?

@hroncok
Copy link
Member

hroncok commented Apr 15, 2021

I think we can make the version check more specific.

@hroncok
Copy link
Member

hroncok commented Apr 15, 2021

I cannot trigger a problem on Python 3.10.0a7, so maybe this is fine.

@The-Compiler
Copy link
Member

FYI, GitHub Actions seems to have pushed a rather weird "beta 1" release which isn't actually beta 1 - so if we're seeing an influx of new reports about this, that'd be why (as python: 3.10-dev now uses that affected release rather than Alpha 7).

@AlirezaTheH
Copy link

I'm still having this issue on Python 3.10.4, pytest 7.1.2!

@asottile
Copy link
Member

@AlirezaTheH please open a new issue with a reproduction

@parsanoori
Copy link

Still have this problem:

git clone https://gitlab.com/nanuchi/gitlab-cicd-crash-course.git
cd gitlab-cicd-crash-course
make test

The output is:

. src/.venv/bin/activate \
&& pytest -v
========================================================= test session starts =========================================================
platform linux -- Python 3.10.4, pytest-6.2.2, py-1.11.0, pluggy-0.13.1 -- /home/parsa/gits/gitlab-cicd-crash-course/src/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /home/parsa/gits/gitlab-cicd-crash-course
collected 0 items / 1 error                                                                                                           

=============================================================== ERRORS ================================================================
____________________________________________________ ERROR collecting test session ____________________________________________________
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
    ???
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
src/.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:161: in exec_module
    source_stat, co = _rewrite_test(fn, self.config)
src/.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:356: in _rewrite_test
    co = compile(tree, fn_, "exec", dont_inherit=True)
E   TypeError: required field "lineno" missing from alias
======================================================= short test summary info =======================================================
ERROR  - TypeError: required field "lineno" missing from alias
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================================== 1 error in 0.23s ===========================================================
make: *** [makefile:56: test] Error 2

Related info:

python3 --version # the command
Python 3.10.4 # the output


python3 -m pytest --version # the command
pytest 7.1.2 # the output

@The-Compiler
Copy link
Member

@parsanoori as seen in the output header, you're actually running pytest 6.2.2 in the virtualenv there.

@parsanoori
Copy link

It's the git maintainer's problem.
Thanks.

abesto added a commit to abesto/ghstack that referenced this pull request Aug 9, 2022
`poetry update pytest` to get
pytest-dev/pytest#8540 for Python 3.10
compatibility
ezyang pushed a commit to ezyang/ghstack that referenced this pull request Aug 9, 2022
`poetry update pytest` to get
pytest-dev/pytest#8540 for Python 3.10
compatibility
sbelluzzo added a commit to sbelluzzo/pipelinewise-target-postgres that referenced this pull request Sep 16, 2022
Resolves assertion rewriting issue when running in Python 3.10.
See pytest-dev/pytest#8540
frodeaa pushed a commit to Dintero/docker-pytest-bdd that referenced this pull request Nov 19, 2022
- Bump pytest from 5.3.4 to 7.2.0

The old version of pytest did not support python3.10

Rel: pytest-dev/pytest#8540
frodeaa pushed a commit to Dintero/docker-pytest-bdd that referenced this pull request Nov 19, 2022
- Bump pytest from 5.3.4 to 7.2.0
- Bump pytest-bdd from 3.2.1 6.1.1

The old version of pytest/pytest-bdd did not support python3.10

Rel: pytest-dev/pytest#8540
frodeaa pushed a commit to Dintero/docker-pytest-bdd that referenced this pull request Nov 19, 2022
- Bump pytest from 5.3.4 to 7.2.0
- Bump pytest-bdd from 3.2.1 4.1.0

The old version of pytest/pytest-bdd did not support python3.10

Rel: pytest-dev/pytest#8540
frodeaa added a commit to Dintero/docker-pytest-bdd that referenced this pull request Nov 20, 2022
Bump pytest and pytes-bdd to get support for python3.10

- pytest from 5.3.4 to 7.2.0
- pytest-bdd from 3.2.1 to 4.1.0 (5 and 6 have to many breaking changes)
  See: https://github.com/pytest-dev/pytest-bdd/blob/master/CHANGES.rst

Bump other dependencies
- boto3
- bravado-core
- cryptography
- pycodestyle
- PyJWT
- pytest-parallel
- requests

The `requirements.txt` was updated wit the output from `pip freeze` after
new version of the dependencies was installed

Rel: pytest-dev/pytest#8540
Jacob-Stevens-Haas added a commit to dynamicslab/pysindy that referenced this pull request Apr 7, 2023
jpcurbelo pushed a commit to jpcurbelo/pysindy_fork that referenced this pull request Apr 30, 2024
oliverjwroberts added a commit to uktrade/dnb-service that referenced this pull request Aug 8, 2024
oliverjwroberts added a commit to uktrade/dnb-service that referenced this pull request Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion rewriting fails under Python 3.10.0a7+
8 participants