Skip to content

Commit 1cc974c

Browse files
authored
[4.6] Fix warnings with attrs 19.2 and fix object assertions (#… (#5944)
[4.6] Fix warnings with attrs 19.2 and fix object assertions (#5902)
2 parents f2d87dc + c03e46f commit 1cc974c

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/_pytest/assertion/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from ..compat import Sequence
1313
from _pytest import outcomes
1414
from _pytest._io.saferepr import saferepr
15+
from _pytest.compat import ATTRS_EQ_FIELD
1516

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

379382
same = []
380383
diff = []

src/_pytest/compat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
from contextlib import contextmanager
1515

16+
import attr
1617
import py
1718
import six
1819
from six import text_type
@@ -406,8 +407,8 @@ def _setup_collect_fakemodule():
406407

407408
pytest.collect = ModuleType("pytest.collect")
408409
pytest.collect.__all__ = [] # used for setns
409-
for attr in COLLECT_FAKEMODULE_ATTRIBUTES:
410-
setattr(pytest.collect, attr, getattr(pytest, attr))
410+
for attribute in COLLECT_FAKEMODULE_ATTRIBUTES:
411+
setattr(pytest.collect, attribute, getattr(pytest, attribute))
411412

412413

413414
if _PY2:
@@ -455,3 +456,9 @@ def dec(fn):
455456

456457
else:
457458
from functools import lru_cache # noqa: F401
459+
460+
461+
if getattr(attr, "__version_info__", ()) >= (19, 2):
462+
ATTRS_EQ_FIELD = "eq"
463+
else:
464+
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 six
99

1010
from ..compat import ascii_escaped
11+
from ..compat import ATTRS_EQ_FIELD
1112
from ..compat import getfslineno
1213
from ..compat import MappingMixin
1314
from ..compat import NOTSET
@@ -377,7 +378,8 @@ def __repr__(self):
377378
return "<NodeKeywords for node %s>" % (self.node,)
378379

379380

380-
@attr.s(cmp=False, hash=False)
381+
# mypy cannot find this overload, remove when on attrs>=19.2
382+
@attr.s(hash=False, **{ATTRS_EQ_FIELD: False}) # type: ignore
381383
class NodeMarkers(object):
382384
"""
383385
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
@@ -14,6 +14,7 @@
1414
from _pytest import outcomes
1515
from _pytest.assertion import truncate
1616
from _pytest.assertion import util
17+
from _pytest.compat import ATTRS_EQ_FIELD
1718

1819
PY3 = sys.version_info >= (3, 0)
1920

@@ -687,7 +688,7 @@ def test_attrs_with_attribute_comparison_off(self):
687688
@attr.s
688689
class SimpleDataObject(object):
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)