From 32bb8f3a63ceaf19c925fc941d1fb872abd1b36a Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 23 Sep 2020 14:28:10 +0300 Subject: [PATCH] Bump attrs requirement from >=17.4.0 to >=19.2.0 This allows us to remove the `ATTRS_EQ_FIELD` thing which is causing some annoyance. --- .github/workflows/main.yml | 2 +- changelog/7802.trivial.rst | 1 + setup.cfg | 2 +- src/_pytest/_code/code.py | 21 ++++++++++----------- src/_pytest/assertion/util.py | 5 +---- src/_pytest/compat.py | 6 ------ testing/test_assertion.py | 3 +-- testing/test_meta.py | 2 -- testing/test_unittest.py | 6 +----- tox.ini | 2 -- 10 files changed, 16 insertions(+), 34 deletions(-) create mode 100644 changelog/7802.trivial.rst diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ef1a08b9..84b7de5f8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -79,7 +79,7 @@ jobs: - name: "ubuntu-py37" python: "3.7" os: ubuntu-latest - tox_env: "py37-lsof-numpy-oldattrs-pexpect" + tox_env: "py37-lsof-numpy-pexpect" use_coverage: true - name: "ubuntu-py37-pluggy" python: "3.7" diff --git a/changelog/7802.trivial.rst b/changelog/7802.trivial.rst new file mode 100644 index 000000000..1f8bc2c9d --- /dev/null +++ b/changelog/7802.trivial.rst @@ -0,0 +1 @@ +The ``attrs`` dependency requirement is now >=19.2.0 instead of >=17.4.0. diff --git a/setup.cfg b/setup.cfg index f4170f15a..6b54fc370 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ packages = _pytest.mark pytest install_requires = - attrs>=17.4.0 + attrs>=19.2.0 iniconfig packaging pluggy>=0.12,<1.0 diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 5063e6604..6b908bb51 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -37,7 +37,6 @@ from _pytest._code.source import Source from _pytest._io import TerminalWriter from _pytest._io.saferepr import safeformat from _pytest._io.saferepr import saferepr -from _pytest.compat import ATTRS_EQ_FIELD from _pytest.compat import final from _pytest.compat import get_real_func from _pytest.compat import overload @@ -918,7 +917,7 @@ class FormattedExcinfo: return ExceptionChainRepr(repr_chain) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class TerminalRepr: def __str__(self) -> str: # FYI this is called from pytest-xdist's serialization of exception @@ -936,7 +935,7 @@ class TerminalRepr: # This class is abstract -- only subclasses are instantiated. -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ExceptionRepr(TerminalRepr): # Provided by subclasses. reprcrash = None # type: Optional[ReprFileLocation] @@ -954,7 +953,7 @@ class ExceptionRepr(TerminalRepr): tw.line(content) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ExceptionChainRepr(ExceptionRepr): chain = attr.ib( type=Sequence[ @@ -978,7 +977,7 @@ class ExceptionChainRepr(ExceptionRepr): super().toterminal(tw) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ReprExceptionInfo(ExceptionRepr): reprtraceback = attr.ib(type="ReprTraceback") reprcrash = attr.ib(type="ReprFileLocation") @@ -988,7 +987,7 @@ class ReprExceptionInfo(ExceptionRepr): super().toterminal(tw) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ReprTraceback(TerminalRepr): reprentries = attr.ib(type=Sequence[Union["ReprEntry", "ReprEntryNative"]]) extraline = attr.ib(type=Optional[str]) @@ -1022,7 +1021,7 @@ class ReprTracebackNative(ReprTraceback): self.extraline = None -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ReprEntryNative(TerminalRepr): lines = attr.ib(type=Sequence[str]) style = "native" # type: _TracebackStyle @@ -1031,7 +1030,7 @@ class ReprEntryNative(TerminalRepr): tw.write("".join(self.lines)) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ReprEntry(TerminalRepr): lines = attr.ib(type=Sequence[str]) reprfuncargs = attr.ib(type=Optional["ReprFuncArgs"]) @@ -1111,7 +1110,7 @@ class ReprEntry(TerminalRepr): ) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ReprFileLocation(TerminalRepr): path = attr.ib(type=str, converter=str) lineno = attr.ib(type=int) @@ -1128,7 +1127,7 @@ class ReprFileLocation(TerminalRepr): tw.line(":{}: {}".format(self.lineno, msg)) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ReprLocals(TerminalRepr): lines = attr.ib(type=Sequence[str]) @@ -1137,7 +1136,7 @@ class ReprLocals(TerminalRepr): tw.line(indent + line) -@attr.s(**{ATTRS_EQ_FIELD: False}) # type: ignore +@attr.s(eq=False) class ReprFuncArgs(TerminalRepr): args = attr.ib(type=Sequence[Tuple[str, object]]) diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index e80e476c8..1d0e903cd 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -16,7 +16,6 @@ from _pytest import outcomes from _pytest._io.saferepr import _pformat_dispatch from _pytest._io.saferepr import safeformat 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 # interpretation code and assertion rewriter to detect this plugin was @@ -420,9 +419,7 @@ def _compare_eq_cls( fields_to_check = [field for field, info in all_fields.items() if info.compare] elif isattrs(left): all_fields = left.__attrs_attrs__ - fields_to_check = [ - field.name for field in all_fields if getattr(field, ATTRS_EQ_FIELD) - ] + fields_to_check = [field.name for field in all_fields if getattr(field, "eq")] indent = " " same = [] diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index 7eab2ea0c..33221aac2 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -371,12 +371,6 @@ else: return f -if getattr(attr, "__version_info__", ()) >= (19, 2): - ATTRS_EQ_FIELD = "eq" -else: - ATTRS_EQ_FIELD = "cmp" - - if sys.version_info >= (3, 8): from functools import cached_property as cached_property else: diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 1cb63a329..258be48b8 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -12,7 +12,6 @@ import pytest from _pytest import outcomes from _pytest.assertion import truncate from _pytest.assertion import util -from _pytest.compat import ATTRS_EQ_FIELD def mock_config(verbose=0): @@ -945,7 +944,7 @@ class TestAssert_reprcompare_attrsclass: @attr.s class SimpleDataObject: field_a = attr.ib() - field_b = attr.ib(**{ATTRS_EQ_FIELD: False}) # type: ignore + field_b = attr.ib(eq=False) left = SimpleDataObject(1, "b") right = SimpleDataObject(1, "b") diff --git a/testing/test_meta.py b/testing/test_meta.py index 1acf6d09f..97b2e1a1a 100644 --- a/testing/test_meta.py +++ b/testing/test_meta.py @@ -27,8 +27,6 @@ def test_no_warnings(module: str) -> None: subprocess.check_call(( sys.executable, "-W", "error", - # https://github.com/pytest-dev/pytest/issues/5901 - "-W", "ignore:The usage of `cmp` is deprecated and will be removed on or after 2021-06-01. Please use `eq` and `order` instead.:DeprecationWarning", # noqa: E501 "-c", "__import__({!r})".format(module), )) # fmt: on diff --git a/testing/test_unittest.py b/testing/test_unittest.py index c7b6bfcec..f3f4d4e06 100644 --- a/testing/test_unittest.py +++ b/testing/test_unittest.py @@ -532,11 +532,7 @@ class TestTrialUnittest: # will crash both at test time and at teardown """ ) - # Ignore DeprecationWarning (for `cmp`) from attrs through twisted, - # for stable test results. - result = testdir.runpytest( - "-vv", "-oconsole_output_style=classic", "-W", "ignore::DeprecationWarning" - ) + result = testdir.runpytest("-vv", "-oconsole_output_style=classic") result.stdout.fnmatch_lines( [ "test_trial_error.py::TC::test_four FAILED", diff --git a/tox.ini b/tox.ini index b42aecdf8..3e96ef49b 100644 --- a/tox.ini +++ b/tox.ini @@ -45,8 +45,6 @@ setenv = extras = testing deps = doctesting: PyYAML - oldattrs: attrs==17.4.0 - oldattrs: hypothesis<=4.38.1 numpy: numpy pexpect: pexpect pluggymaster: git+https://github.com/pytest-dev/pluggy.git@master