From 6f7a95c32e4b99a8dd4ccbe57af6b73c51597735 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 15 Jan 2020 10:08:30 +0100 Subject: [PATCH] tests: cover safe_getattr --- testing/test_compat.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/testing/test_compat.py b/testing/test_compat.py index 04d818b4e..45468b5f8 100644 --- a/testing/test_compat.py +++ b/testing/test_compat.py @@ -146,12 +146,16 @@ def test_is_generator_async_gen_syntax(testdir): class ErrorsHelper: + @property + def raise_baseexception(self): + raise BaseException("base exception should be raised") + @property def raise_exception(self): raise Exception("exception should be catched") @property - def raise_fail(self): + def raise_fail_outcome(self): pytest.fail("fail should be catched") @@ -160,13 +164,15 @@ def test_helper_failures(): with pytest.raises(Exception): helper.raise_exception with pytest.raises(OutcomeException): - helper.raise_fail + helper.raise_fail_outcome def test_safe_getattr(): helper = ErrorsHelper() assert safe_getattr(helper, "raise_exception", "default") == "default" - assert safe_getattr(helper, "raise_fail", "default") == "default" + assert safe_getattr(helper, "raise_fail_outcome", "default") == "default" + with pytest.raises(BaseException): + assert safe_getattr(helper, "raise_baseexception", "default") def test_safe_isclass():