Merge pull request #6466 from blueyed/cover-safe_getattr
tests: cover safe_getattr
This commit is contained in:
commit
29703a5f51
|
@ -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():
|
||||
|
|
Loading…
Reference in New Issue