Skip to content

Walrus operator causes different behavior in PyTest. #10743

Closed
@veritas9872

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)

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