From 5c04674e96f3586aa943b8a3a63741b81ff00ab7 Mon Sep 17 00:00:00 2001 From: Graeme Smecher Date: Mon, 12 Jul 2021 12:27:24 -0700 Subject: [PATCH 1/2] Generate useful parameterization IDs for complex() numbers. --- AUTHORS | 1 + changelog/8898.trivial.rst | 1 + src/_pytest/python.py | 2 +- testing/python/metafunc.py | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelog/8898.trivial.rst diff --git a/AUTHORS b/AUTHORS index 16a53d94b..d6004f33d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -125,6 +125,7 @@ Gene Wood George Kussumoto Georgy Dyuldin Gleb Nikonorov +Graeme Smecher Graham Horler Greg Price Gregory Lee diff --git a/changelog/8898.trivial.rst b/changelog/8898.trivial.rst new file mode 100644 index 000000000..d725157cf --- /dev/null +++ b/changelog/8898.trivial.rst @@ -0,0 +1 @@ +Complex numbers are now treated like floats and integers when generating parameterization IDs. diff --git a/src/_pytest/python.py b/src/_pytest/python.py index f7dfd696b..d6c14ea52 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1334,7 +1334,7 @@ def _idval( if isinstance(val, STRING_TYPES): return _ascii_escaped_by_config(val, config) - elif val is None or isinstance(val, (float, int, bool)): + elif val is None or isinstance(val, (float, int, bool, complex)): return str(val) elif isinstance(val, REGEX_TYPE): return ascii_escaped(val.pattern) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 4a4b141c4..ccf9c1d9c 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -403,6 +403,7 @@ class TestMetafunc: pytest.param(tuple("eight"), (8, -8, 8)), pytest.param(b"\xc3\xb4", b"name"), pytest.param(b"\xc3\xb4", "other"), + pytest.param(1.0j, -2.0j), ], ) assert result == [ @@ -418,6 +419,7 @@ class TestMetafunc: "a9-b9", "\\xc3\\xb4-name", "\\xc3\\xb4-other", + "1j-(-0-2j)", ] def test_idmaker_non_printable_characters(self) -> None: From 3c18a9ecd0aec0e25504219a2ad77431bc1baba3 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 12 Jul 2021 18:09:13 -0300 Subject: [PATCH 2/2] Rename 8898.trivial.rst to 8898.improvement.rst --- changelog/{8898.trivial.rst => 8898.improvement.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog/{8898.trivial.rst => 8898.improvement.rst} (100%) diff --git a/changelog/8898.trivial.rst b/changelog/8898.improvement.rst similarity index 100% rename from changelog/8898.trivial.rst rename to changelog/8898.improvement.rst