def assert_raises(exception, callable=None, *args, **kwargs): if callable: return old_assert_raises(exception, callable, *args, **kwargs) else: return _AssertRaisesContextManager(exception)
import re from nose.tools import assert_raises as old_assert_raises, \ assert_true as old_assert_true, \ assert_false as old_assert_false, \ __all__ as nose_tools_all from nose.tools import * __all__ = nose_tools_all try: # This will throw a TypeError exception on Python < 2.7. old_assert_raises(Exception) except TypeError: __all__ += [ 'assert_is', 'assert_is_not', 'assert_is_none', 'assert_is_not_none', 'assert_in', 'assert_not_in', 'assert_is_instance', 'assert_not_is_instance', 'assert_regexp_matches', 'assert_not_regexp_matches' ] class _AssertRaisesContextManager(object): def __init__(self, expected_exception): super(_AssertRaisesContextManager, self).__init__() self._expected_exception = expected_exception def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb):
from nose.tools import ( assert_raises as old_assert_raises, assert_true as old_assert_true, assert_false as old_assert_false, __all__ as nose_tools_all, ) from nose.tools import * __all__ = nose_tools_all try: # This will throw a TypeError exception on Python < 2.7. old_assert_raises(Exception) except TypeError: __all__ += [ "assert_is", "assert_is_not", "assert_is_none", "assert_is_not_none", "assert_in", "assert_not_in", "assert_is_instance", "assert_not_is_instance", "assert_regexp_matches", "assert_not_regexp_matches", ]