warnings.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # testing/warnings.py
  2. # Copyright (C) 2005-2017 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: http://www.opensource.org/licenses/mit-license.php
  7. from __future__ import absolute_import
  8. import warnings
  9. from .. import exc as sa_exc
  10. from . import assertions
  11. def setup_filters():
  12. """Set global warning behavior for the test suite."""
  13. warnings.filterwarnings('ignore',
  14. category=sa_exc.SAPendingDeprecationWarning)
  15. warnings.filterwarnings('error', category=sa_exc.SADeprecationWarning)
  16. warnings.filterwarnings('error', category=sa_exc.SAWarning)
  17. # some selected deprecations...
  18. warnings.filterwarnings('error', category=DeprecationWarning)
  19. warnings.filterwarnings(
  20. "ignore", category=DeprecationWarning, message=".*StopIteration")
  21. warnings.filterwarnings(
  22. "ignore", category=DeprecationWarning, message=".*inspect.getargspec")
  23. def assert_warnings(fn, warning_msgs, regex=False):
  24. """Assert that each of the given warnings are emitted by fn.
  25. Deprecated. Please use assertions.expect_warnings().
  26. """
  27. with assertions._expect_warnings(
  28. sa_exc.SAWarning, warning_msgs, regex=regex):
  29. return fn()