From a74243a02814e2c0aa8bb4ed3171cd55715ea90a Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Mon, 17 Jul 2023 19:51:15 +0200 Subject: [PATCH] Suppport older versions of python --- testing/code/test_excinfo.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 079e270d4..f58dd9e23 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -1650,7 +1650,14 @@ def test_hidden_entries_of_chained_exceptions_are_not_shown(pytester: Pytester) ) -@pytest.mark.skip("sys.version_info < (3,11)") +def add_note(err: BaseException, msg: str) -> None: + """Adds a note to an exception inplace.""" + if sys.version_info < (3, 11): + err.__notes__ = getattr(err, "__notes__", []) + [msg] # type: ignore[attr-defined] + else: + err.add_note(msg) + + @pytest.mark.parametrize( "error,notes,match", [ @@ -1662,23 +1669,23 @@ def test_hidden_entries_of_chained_exceptions_are_not_shown(pytester: Pytester) ) def test_check_error_notes_success(error, notes, match): for note in notes: - error.add_note(note) + add_note(error, note) with pytest.raises(Exception, match=match): raise error -@pytest.mark.skip("sys.version_info < (3,11)") @pytest.mark.parametrize( "error, notes, match", [ (Exception("test"), [], "foo"), (AssertionError("foo"), ["bar"], "baz"), + (AssertionError("foo"), ["bar"], "foo\nbaz"), ], ) def test_check_error_notes_failure(error, notes, match): for note in notes: - error.add_note(note) + add_note(error, note) with pytest.raises(AssertionError): with pytest.raises(type(error), match=match):