Skip to content

Commit 8c9ea5e

Browse files
authored
Fix warnings with attrs 19.2 and fix object assertions (#5902)
Fix warnings with attrs 19.2 and fix object assertions
2 parents 4011af6 + c58b0fb commit 8c9ea5e

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/_pytest/assertion/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import _pytest._code
99
from _pytest import outcomes
1010
from _pytest._io.saferepr import saferepr
11+
from _pytest.compat import ATTRS_EQ_FIELD
1112

1213
# The _reprcompare attribute on the util module is used by the new assertion
1314
# interpretation code and assertion rewriter to detect this plugin was
@@ -375,7 +376,9 @@ def _compare_eq_cls(left, right, verbose, type_fns):
375376
fields_to_check = [field for field, info in all_fields.items() if info.compare]
376377
elif isattrs(left):
377378
all_fields = left.__attrs_attrs__
378-
fields_to_check = [field.name for field in all_fields if field.cmp]
379+
fields_to_check = [
380+
field.name for field in all_fields if getattr(field, ATTRS_EQ_FIELD)
381+
]
379382

380383
same = []
381384
diff = []

src/_pytest/compat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,9 @@ def funcargnames(self):
354354

355355
def overload(f): # noqa: F811
356356
return f
357+
358+
359+
if getattr(attr, "__version_info__", ()) >= (19, 2):
360+
ATTRS_EQ_FIELD = "eq"
361+
else:
362+
ATTRS_EQ_FIELD = "cmp"

src/_pytest/mark/structures.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import attr
99

1010
from ..compat import ascii_escaped
11+
from ..compat import ATTRS_EQ_FIELD
1112
from ..compat import getfslineno
1213
from ..compat import NOTSET
1314
from _pytest.outcomes import fail
@@ -367,7 +368,8 @@ def __repr__(self):
367368
return "<NodeKeywords for node {}>".format(self.node)
368369

369370

370-
@attr.s(cmp=False, hash=False)
371+
# mypy cannot find this overload, remove when on attrs>=19.2
372+
@attr.s(hash=False, **{ATTRS_EQ_FIELD: False}) # type: ignore
371373
class NodeMarkers:
372374
"""
373375
internal structure for storing marks belonging to a node

testing/test_assertion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from _pytest import outcomes
1010
from _pytest.assertion import truncate
1111
from _pytest.assertion import util
12+
from _pytest.compat import ATTRS_EQ_FIELD
1213

1314

1415
def mock_config():
@@ -687,7 +688,7 @@ def test_attrs_with_attribute_comparison_off(self):
687688
@attr.s
688689
class SimpleDataObject:
689690
field_a = attr.ib()
690-
field_b = attr.ib(cmp=False)
691+
field_b = attr.ib(**{ATTRS_EQ_FIELD: False})
691692

692693
left = SimpleDataObject(1, "b")
693694
right = SimpleDataObject(1, "b")

0 commit comments

Comments
 (0)