add exception.ignore

This commit is contained in:
Prodesire 2017-12-17 17:14:32 +08:00
parent f826b33400
commit d6bd7d7214
2 changed files with 16 additions and 0 deletions

9
pydu/exception.py Normal file
View File

@ -0,0 +1,9 @@
from contextlib import contextmanager
@contextmanager
def ignore(*exceptions):
try:
yield
except exceptions:
pass

7
tests/test_exception.py Normal file
View File

@ -0,0 +1,7 @@
from pydu.exception import ignore
def test_ignore():
with ignore(ValueError, AttributeError):
int('abc')
int.no_exists_func()