def test_catch_warning(): class MyWarning(Warning): pass with pytest.raises(MyWarning): with catch_warning(MyWarning): warnings.warn("message", MyWarning)
def test(value): with catch_warning(UnicodeWarning): try: return value == rhs except UnicodeWarning: # Dealing with a case, where 'value' or 'rhs' # is unicode and the other is a byte string. if isinstance(value, str): return value.decode('utf-8') == rhs elif isinstance(rhs, str): return value == rhs.decode('utf-8')
def _cmp(value): with catch_warning(UnicodeWarning): try: return value == other except UnicodeWarning: # Dealing with a case, where 'value' or 'other' # is unicode and the other is a byte string. if isinstance(value, str): return value.decode('utf-8') == other elif isinstance(other, str): return value == other.decode('utf-8')
def test_catch_warning(): class MyWarning(Warning): pass filters = warnings.filters[:] with pytest.raises(MyWarning): with catch_warning(MyWarning): warnings.warn("message", MyWarning) assert filters == warnings.filters
def test_catch_warning_reset_filter(): class MyWarning(Warning): pass warnings.filterwarnings(action='once', category=MyWarning) with pytest.raises(MyWarning): with catch_warning(MyWarning): warnings.warn("message", MyWarning) filter = [f for f in warnings.filters if f[2] == MyWarning] assert filter assert filter[0][0] == 'once'
def test_catch_warning_reset_filter(): class MyWarning(Warning): pass warnings.filterwarnings(action='once', category=MyWarning) with pytest.raises(MyWarning): with catch_warning(MyWarning): warnings.warn("message", MyWarning) filters = [f for f in warnings.filters if f[2] == MyWarning] assert filters assert filters[0][0] == 'once'
def test_smart_query_cache_via_kwarg(db): # For backwards compatibility with pytest.raises(DeprecationWarning): with catch_warning(DeprecationWarning): table = db.table('table3', smart_cache=True) assert isinstance(table, SmartCacheTable)