Skip to content

Walrus operator causes different behavior in PyTest. #10743

Description

@veritas9872

I am currently testing the following function but find that the function passes the test in the normal Python terminal but fails in a PyTest run. The walrus operator is relatively new and not many people use it. I think that there may be an inconsistency in the execution environment.

import numpy as np

def test_walrus_conversion():
    a = np.random.random(16)
    assert not np.array_equal(a, a := a.astype(np.uint8))
    assert np.all(a == 0)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs backportapplied to PRs, indicates that it should be ported to the current bug-fix branchtopic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions