Skip to content

Commit f9ff913

Browse files
Fix test_ne in test_cmp.py for Python 3.13 (#1255)
* Fix test_ne in test_cmp.py for Python 3.13 Compiler in Python 3.13+ strips indents from docstrings so they need to be compared without it for new Pythons. Fixes: python-attrs/attrs#1228 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b9084fa commit f9ff913

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/attr/_compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PY_3_9_PLUS = sys.version_info[:2] >= (3, 9)
1515
PY310 = sys.version_info[:2] >= (3, 10)
1616
PY_3_12_PLUS = sys.version_info[:2] >= (3, 12)
17+
PY_3_13_PLUS = sys.version_info[:2] >= (3, 13)
1718

1819

1920
if sys.version_info < (3, 8):

tests/test_cmp.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
Tests for methods from `attrib._cmp`.
55
"""
66

7-
87
import pytest
98

109
from attr._cmp import cmp_using
10+
from attr._compat import PY_3_13_PLUS
1111

1212

1313
# Test parameters.
@@ -54,6 +54,9 @@
5454
cmp_data = eq_data + order_data
5555
cmp_ids = eq_ids + order_ids
5656

57+
# Compiler strips indents from docstrings in Python 3.13+
58+
indent = "" if PY_3_13_PLUS else " " * 8
59+
5760

5861
class TestEqOrder:
5962
"""
@@ -325,7 +328,7 @@ def test_ne(self):
325328
method = self.cls.__ne__
326329
assert method.__doc__.strip() == (
327330
"Check equality and either forward a NotImplemented or\n"
328-
" return the result negated."
331+
f"{indent}return the result negated."
329332
)
330333
assert method.__name__ == "__ne__"
331334

@@ -393,7 +396,7 @@ def test_ne(self):
393396
method = self.cls.__ne__
394397
assert method.__doc__.strip() == (
395398
"Check equality and either forward a NotImplemented or\n"
396-
" return the result negated."
399+
f"{indent}return the result negated."
397400
)
398401
assert method.__name__ == "__ne__"
399402

@@ -465,7 +468,7 @@ def test_ne(self):
465468
method = self.cls.__ne__
466469
assert method.__doc__.strip() == (
467470
"Check equality and either forward a NotImplemented or\n"
468-
" return the result negated."
471+
f"{indent}return the result negated."
469472
)
470473
assert method.__name__ == "__ne__"
471474

0 commit comments

Comments
 (0)