From 143141ab161ed2567bf2ae5390d8bc85815b77fd Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Wed, 20 Dec 2023 12:38:43 +0100 Subject: [PATCH] correct fix --- anndata/tests/helpers.py | 3 +-- anndata/tests/test_io_utils.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/anndata/tests/helpers.py b/anndata/tests/helpers.py index fc4b57c80..316fc991e 100644 --- a/anndata/tests/helpers.py +++ b/anndata/tests/helpers.py @@ -651,8 +651,7 @@ def check_error_or_notes_match(e: pytest.ExceptionInfo, pattern: str | re.Patter import traceback message = "".join(traceback.format_exception_only(e.type, e.value)) - # To match pytest semantics, this must be `match`, not `search`. - assert re.match( + assert re.search( pattern, message ), f"Could not find pattern: '{pattern}' in error:\n\n{message}\n" diff --git a/anndata/tests/test_io_utils.py b/anndata/tests/test_io_utils.py index df5d70c84..453beaccd 100644 --- a/anndata/tests/test_io_utils.py +++ b/anndata/tests/test_io_utils.py @@ -39,10 +39,10 @@ def read_attr(_): group["X"] = [1, 2, 3] group.create_group("group") - with pytest_8_raises(NotImplementedError, match=r"/X"): + with pytest_8_raises(NotImplementedError, match=r".*/X$"): read_attr(group["X"]) - with pytest_8_raises(NotImplementedError, match=r"/group"): + with pytest_8_raises(NotImplementedError, match=r".*/group$"): read_attr(group["group"]) @@ -91,7 +91,7 @@ class Foo: # (?!...) is a negative lookahead # (?s) enables the dot to match newlines # https://stackoverflow.com/a/406408/130164 <- copilot suggested lol - pattern = r"(?s)((?!Error raised while writing key '/?a').)*$" + pattern = r"(?s)^((?!Error raised while writing key '/?a').)*$" with pytest_8_raises(IORegistryError, match=pattern): write_elem(group, "/", {"a": {"b": Foo()}})