Skip to content

Commit d0bd269

Browse files
Merge pull request #8899 from gsmecher/parameterize-complex-numbers
Generate useful parameterization IDs for complex() numbers.
2 parents 5165bf9 + 3c18a9e commit d0bd269

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Gene Wood
125125
George Kussumoto
126126
Georgy Dyuldin
127127
Gleb Nikonorov
128+
Graeme Smecher
128129
Graham Horler
129130
Greg Price
130131
Gregory Lee

changelog/8898.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Complex numbers are now treated like floats and integers when generating parameterization IDs.

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def _idval(
13341334

13351335
if isinstance(val, STRING_TYPES):
13361336
return _ascii_escaped_by_config(val, config)
1337-
elif val is None or isinstance(val, (float, int, bool)):
1337+
elif val is None or isinstance(val, (float, int, bool, complex)):
13381338
return str(val)
13391339
elif isinstance(val, REGEX_TYPE):
13401340
return ascii_escaped(val.pattern)

testing/python/metafunc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ def test_idmaker_native_strings(self) -> None:
403403
pytest.param(tuple("eight"), (8, -8, 8)),
404404
pytest.param(b"\xc3\xb4", b"name"),
405405
pytest.param(b"\xc3\xb4", "other"),
406+
pytest.param(1.0j, -2.0j),
406407
],
407408
)
408409
assert result == [
@@ -418,6 +419,7 @@ def test_idmaker_native_strings(self) -> None:
418419
"a9-b9",
419420
"\\xc3\\xb4-name",
420421
"\\xc3\\xb4-other",
422+
"1j-(-0-2j)",
421423
]
422424

423425
def test_idmaker_non_printable_characters(self) -> None:

0 commit comments

Comments
 (0)