Fix warnings with attrs 19.2 and fix object assertions (#5902)
Fix warnings with attrs 19.2 and fix object assertions
This commit is contained in:
commit
8c9ea5e055
|
@ -8,6 +8,7 @@ from typing import Optional
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
from _pytest import outcomes
|
from _pytest import outcomes
|
||||||
from _pytest._io.saferepr import saferepr
|
from _pytest._io.saferepr import saferepr
|
||||||
|
from _pytest.compat import ATTRS_EQ_FIELD
|
||||||
|
|
||||||
# The _reprcompare attribute on the util module is used by the new assertion
|
# The _reprcompare attribute on the util module is used by the new assertion
|
||||||
# interpretation code and assertion rewriter to detect this plugin was
|
# interpretation code and assertion rewriter to detect this plugin was
|
||||||
|
@ -375,7 +376,9 @@ def _compare_eq_cls(left, right, verbose, type_fns):
|
||||||
fields_to_check = [field for field, info in all_fields.items() if info.compare]
|
fields_to_check = [field for field, info in all_fields.items() if info.compare]
|
||||||
elif isattrs(left):
|
elif isattrs(left):
|
||||||
all_fields = left.__attrs_attrs__
|
all_fields = left.__attrs_attrs__
|
||||||
fields_to_check = [field.name for field in all_fields if field.cmp]
|
fields_to_check = [
|
||||||
|
field.name for field in all_fields if getattr(field, ATTRS_EQ_FIELD)
|
||||||
|
]
|
||||||
|
|
||||||
same = []
|
same = []
|
||||||
diff = []
|
diff = []
|
||||||
|
|
|
@ -354,3 +354,9 @@ if sys.version_info < (3, 5, 2): # pragma: no cover
|
||||||
|
|
||||||
def overload(f): # noqa: F811
|
def overload(f): # noqa: F811
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
if getattr(attr, "__version_info__", ()) >= (19, 2):
|
||||||
|
ATTRS_EQ_FIELD = "eq"
|
||||||
|
else:
|
||||||
|
ATTRS_EQ_FIELD = "cmp"
|
||||||
|
|
|
@ -8,6 +8,7 @@ from typing import Set
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
from ..compat import ascii_escaped
|
from ..compat import ascii_escaped
|
||||||
|
from ..compat import ATTRS_EQ_FIELD
|
||||||
from ..compat import getfslineno
|
from ..compat import getfslineno
|
||||||
from ..compat import NOTSET
|
from ..compat import NOTSET
|
||||||
from _pytest.outcomes import fail
|
from _pytest.outcomes import fail
|
||||||
|
@ -367,7 +368,8 @@ class NodeKeywords(MutableMapping):
|
||||||
return "<NodeKeywords for node {}>".format(self.node)
|
return "<NodeKeywords for node {}>".format(self.node)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(cmp=False, hash=False)
|
# mypy cannot find this overload, remove when on attrs>=19.2
|
||||||
|
@attr.s(hash=False, **{ATTRS_EQ_FIELD: False}) # type: ignore
|
||||||
class NodeMarkers:
|
class NodeMarkers:
|
||||||
"""
|
"""
|
||||||
internal structure for storing marks belonging to a node
|
internal structure for storing marks belonging to a node
|
||||||
|
|
|
@ -9,6 +9,7 @@ import pytest
|
||||||
from _pytest import outcomes
|
from _pytest import outcomes
|
||||||
from _pytest.assertion import truncate
|
from _pytest.assertion import truncate
|
||||||
from _pytest.assertion import util
|
from _pytest.assertion import util
|
||||||
|
from _pytest.compat import ATTRS_EQ_FIELD
|
||||||
|
|
||||||
|
|
||||||
def mock_config():
|
def mock_config():
|
||||||
|
@ -687,7 +688,7 @@ class TestAssert_reprcompare_attrsclass:
|
||||||
@attr.s
|
@attr.s
|
||||||
class SimpleDataObject:
|
class SimpleDataObject:
|
||||||
field_a = attr.ib()
|
field_a = attr.ib()
|
||||||
field_b = attr.ib(cmp=False)
|
field_b = attr.ib(**{ATTRS_EQ_FIELD: False})
|
||||||
|
|
||||||
left = SimpleDataObject(1, "b")
|
left = SimpleDataObject(1, "b")
|
||||||
right = SimpleDataObject(1, "b")
|
right = SimpleDataObject(1, "b")
|
||||||
|
|
Loading…
Reference in New Issue