from alembic import util # noqa
from .assertions import assert_raises # noqa
from .assertions import assert_raises_message # noqa
+from .assertions import emits_python_deprecation_warning # noqa
from .assertions import eq_ # noqa
from .assertions import eq_ignore_whitespace # noqa
from .assertions import is_ # noqa
return decorate
+def emits_python_deprecation_warning(*messages):
+ """Decorator form of expect_warnings().
+
+ Note that emits_warning does **not** assert that the warnings
+ were in fact seen.
+
+ """
+
+ @decorator
+ def decorate(fn, *args, **kw):
+ with _expect_warnings(DeprecationWarning, assert_=False, *messages):
+ return fn(*args, **kw)
+
+ return decorate
+
+
def emits_warning_on(db, *messages):
"""Mark a test as emitting a warning on a specific dialect.
return suffixes
def has_pep3147():
- # http://www.python.org/dev/peps/pep-3147/#detecting-pep-3147-availability
- import imp
+ if py35:
+ return True
+ else:
+ # TODO: not sure if we are supporting old versions of Python
+ # the import here emits a deprecation warning which the test
+ # suite only catches if imp wasn't imported alreadt
+ # http://www.python.org/dev/peps/pep-3147/#detecting-pep-3147-availability
+ import imp
- return hasattr(imp, "get_tag")
+ return hasattr(imp, "get_tag")
else:
from .compat import has_pep3147
from .compat import load_module_py
from .compat import load_module_pyc
+from .compat import py35
from .exc import CommandError
"""
if has_pep3147():
- import imp
+ if py35:
+ import importlib
- candidate = imp.cache_from_source(path)
+ candidate = importlib.util.cache_from_source(path)
+ else:
+ import imp
+
+ candidate = imp.cache_from_source(path)
if os.path.exists(candidate):
return candidate
+ # even for pep3147, fall back to the old way of finding .pyc files,
+ # to support sourceless operation
filepath, ext = os.path.splitext(path)
for ext in get_current_bytecode_suffixes():
if os.path.exists(filepath + ext):
--- /dev/null
+.. change::
+ :tag: bug, py3k
+
+ Fixed use of the deprecated "imp" module, which is used to detect pep3147
+ availability as well as to locate .pyc files, which started emitting
+ deprecation warnings during the test suite. The warnings were not being
+ emitted earlier during the test suite, the change is possibly due to
+ changes in py.test itself but this is not clear. The check for pep3147 is
+ set to True for any Python version 3.5 or greater now and importlib is used
+ when available. Note that some dependencies such as distutils may still be
+ emitting this warning. Tests are adjusted to accommodate for dependencies
+ that emit the warning as well.
+
from alembic import command
from alembic import config
+from alembic import testing
from alembic import util
from alembic.script import ScriptDirectory
from alembic.testing import assert_raises
command.edit(self.cfg, self.b[0:3])
edit.assert_called_with(expected_call_arg)
+ @testing.emits_python_deprecation_warning("the imp module is deprecated")
def test_edit_with_missing_editor(self):
with mock.patch("editor.edit") as edit_mock:
edit_mock.side_effect = OSError("file not found")
cov: pytest-cov
+
usedevelop=
cov: True
flake8-builtins
flake8-docstrings
flake8-rst-docstrings
+ pydocstyle<4.0.0
# used by flake8-rst-docstrings
pygments
commands = flake8 ./alembic/ ./tests/ setup.py docs/build/conf.py