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

Pytest reevaluates walrus operations within assert statements #11115

Open
4 tasks done
regananalytics opened this issue Jun 15, 2023 · 4 comments
Open
4 tasks done

Pytest reevaluates walrus operations within assert statements #11115

regananalytics opened this issue Jun 15, 2023 · 4 comments
Labels
topic: rewrite related to the assertion rewrite mechanism type: regression indicates a problem that was introduced in a release which was working previously

Comments

@regananalytics
Copy link

regananalytics commented Jun 15, 2023

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Ubuntu 22.04, pytest 7.3.2, python 3.10.11

Package Version


exceptiongroup 1.1.1
iniconfig 2.0.0
packaging 23.1
pip 23.1.2
pluggy 1.0.0
pytest 7.3.2
setuptools 67.8.0
tomli 2.0.1
wheel 0.38.4

Pytest 7.3.2 re-evaluates walrus operator statements if they appear in assert statements.

def test_walrus():
    assert (x := 2) == 2
    x  =  3
    assert x == 3, "This test fails because (x := 2) is reevaluated by pytest"
    
def test_walrus_no_assert():
    (x := 2) == 2
    x = 3
    assert x == 3, "This test passes because (x := 2) is not reevaluated"
@The-Compiler
Copy link
Member

The-Compiler commented Jun 15, 2023

Bisected to 331bc1b:

As a workaround, --assert=plain works.

cc @aless10

@The-Compiler The-Compiler added type: regression indicates a problem that was introduced in a release which was working previously topic: rewrite related to the assertion rewrite mechanism labels Jun 15, 2023
@aless10
Copy link
Contributor

aless10 commented Jun 19, 2023

Oh no! I'm thinking that a lot of edge cases are really really "edge", and I hope that nobody writes tests like this one. But I'm going to look at this. Is that ok with you?
Thanks

@regananalytics
Copy link
Author

Yeah, this is obviously not a real test. I wrote it as a super simple and replicable example of the issue.

@The-Compiler
Copy link
Member

@aless10 Sure, please go ahead! No worries, sometimes things can be unexpectedly tricky. It's much appreciated that you're taking care of those follow-up issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: rewrite related to the assertion rewrite mechanism type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

3 participants