/Windows/Python3.8/WPy64-3830/WPy64-3830/python-3.8.3.amd64/Lib/site-packages/sqlalchemy/testing/warnings.py

https://gitlab.com/abhi1tb/build · Python · 61 lines · 36 code · 12 blank · 13 comment · 4 complexity · e10644d266a2ab4ac0b16d05f301ac3b MD5 · raw file

  1. # testing/warnings.py
  2. # Copyright (C) 2005-2020 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 assertions
  10. from .. import exc as sa_exc
  11. def setup_filters():
  12. """Set global warning behavior for the test suite."""
  13. warnings.filterwarnings(
  14. "ignore", category=sa_exc.SAPendingDeprecationWarning
  15. )
  16. warnings.filterwarnings("error", category=sa_exc.SADeprecationWarning)
  17. warnings.filterwarnings("error", category=sa_exc.SAWarning)
  18. warnings.filterwarnings(
  19. "ignore",
  20. category=sa_exc.SAWarning,
  21. message=r"Oracle compatibility version .* is known to have a "
  22. "maximum identifier",
  23. )
  24. # some selected deprecations...
  25. warnings.filterwarnings("error", category=DeprecationWarning)
  26. warnings.filterwarnings(
  27. "ignore", category=DeprecationWarning, message=".*StopIteration"
  28. )
  29. warnings.filterwarnings(
  30. "ignore", category=DeprecationWarning, message=".*inspect.getargspec"
  31. )
  32. try:
  33. import pytest
  34. except ImportError:
  35. pass
  36. else:
  37. warnings.filterwarnings(
  38. "once", category=pytest.PytestDeprecationWarning
  39. )
  40. def assert_warnings(fn, warning_msgs, regex=False):
  41. """Assert that each of the given warnings are emitted by fn.
  42. Deprecated. Please use assertions.expect_warnings().
  43. """
  44. with assertions._expect_warnings(
  45. sa_exc.SAWarning, warning_msgs, regex=regex
  46. ):
  47. return fn()