Merge pull request #6466 from blueyed/cover-safe_getattr

tests: cover safe_getattr
This commit is contained in:
Daniel Hahler 2020-01-15 11:20:42 +01:00 committed by GitHub
commit 29703a5f51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -146,12 +146,16 @@ def test_is_generator_async_gen_syntax(testdir):
class ErrorsHelper: class ErrorsHelper:
@property
def raise_baseexception(self):
raise BaseException("base exception should be raised")
@property @property
def raise_exception(self): def raise_exception(self):
raise Exception("exception should be catched") raise Exception("exception should be catched")
@property @property
def raise_fail(self): def raise_fail_outcome(self):
pytest.fail("fail should be catched") pytest.fail("fail should be catched")
@ -160,13 +164,15 @@ def test_helper_failures():
with pytest.raises(Exception): with pytest.raises(Exception):
helper.raise_exception helper.raise_exception
with pytest.raises(OutcomeException): with pytest.raises(OutcomeException):
helper.raise_fail helper.raise_fail_outcome
def test_safe_getattr(): def test_safe_getattr():
helper = ErrorsHelper() helper = ErrorsHelper()
assert safe_getattr(helper, "raise_exception", "default") == "default" 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(): def test_safe_isclass():