Skip to content

CI fails with attrs 25.2.0 #13290

Description

@jakkdl

As seen in https://github.com/pytest-dev/pytest/actions/runs/13810374238 we're getting failing runs from attrs==25.2 in testing/test_assertion.py TestAssert_reprcompare_attrsclass

I bisected it to python-attrs/attrs#1407 - but am unfamiliar with both attr and the parts of pytest interacting with it so am leaving further exploration for somebody else.

Activity

  1. The-Compiler commented on Mar 12, 2025

    @The-Compiler
    Member

    Culprit seems to be here:

    def has_default_eq(
    obj: object,
    ) -> bool:
    """Check if an instance of an object contains the default eq
    First, we check if the object's __eq__ attribute has __code__,
    if so, we check the equally of the method code filename (__code__.co_filename)
    to the default one generated by the dataclass and attr module
    for dataclasses the default co_filename is <string>, for attrs class, the __eq__ should contain "attrs eq generated"
    """
    # inspired from https://github.com/willmcgugan/rich/blob/07d51ffc1aee6f16bd2e5a25b4e82850fb9ed778/rich/pretty.py#L68
    if hasattr(obj.__eq__, "__code__") and hasattr(obj.__eq__.__code__, "co_filename"):
    code_filename = obj.__eq__.__code__.co_filename
    if isattrs(obj):
    return "attrs generated eq" in code_filename

    with attrs 25.1, objects show:

    (Pdb) p code_filename
    '<attrs generated eq test_assertion.TestAssert_reprcompare_attrsclass.test_attrs.<locals>.SimpleDataObject>'
    

    but with 25.2:

    (Pdb) p code_filename
    '<attrs generated methods test_assertion.TestAssert_reprcompare_attrsclass.test_attrs.<locals>.SimpleDataObject>'
    

    which also aligns with test changes in the PR you linked.

    So I think all that'd be required is:

    diff --git i/src/_pytest/assertion/util.py w/src/_pytest/assertion/util.py
    index 30aee185d..c545e6cd2 100644
    --- i/src/_pytest/assertion/util.py
    +++ w/src/_pytest/assertion/util.py
    @@ -169,7 +169,7 @@ def has_default_eq(
             code_filename = obj.__eq__.__code__.co_filename
     
             if isattrs(obj):
    -            return "attrs generated eq" in code_filename
    +            return "attrs generated " in code_filename
     
             return code_filename == "<string>"  # data class
         return True
    
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

    status: help wanteddevelopers would like help from experts on this topic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions