From 8690940976544f368dad31cfbc46d9e1426b2ce1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 26 Sep 2020 21:05:53 -0400 Subject: [PATCH] Support pytest 6.x pytest has removed support for pytest.Class(..parent) and we need to use from_parent. Also works around new issue for 6.1.0 References: https://github.com/pytest-dev/pytest/issues/7807 Change-Id: Ia5fed9b22e76c99f71489283acee207f996f52a4 --- alembic/__init__.py | 2 +- alembic/testing/plugin/pytestplugin.py | 10 ++-------- tox.ini | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) sys.modules["alembic.migration"] = migration sys.modules["alembic.environment"] = environment diff --git a/alembic/testing/plugin/pytestplugin.py b/alembic/testing/plugin/pytestplugin.py index 1c8be05..ba3d35b 100644 --- a/alembic/testing/plugin/pytestplugin.py +++ b/alembic/testing/plugin/pytestplugin.py @@ -33,16 +33,10 @@ def pytest_configure(config): def pytest_pycollect_makeitem(collector, name, obj): if inspect.isclass(obj) and plugin_base.want_class(name, obj): - - # in pytest 5.4.0 - # return [ - # pytest.Class.from_parent(collector, - # name=parametrize_cls.__name__) - # for parametrize_cls in _parametrize_cls(collector.module, obj) - # ] + ctor = getattr(pytest.Class, "from_parent", pytest.Class) return [ - pytest.Class(parametrize_cls.__name__, parent=collector) + ctor(name=parametrize_cls.__name__, parent=collector) for parametrize_cls in _parametrize_cls(collector.module, obj) ] elif ( diff --git a/tox.ini b/tox.ini index ed233ee..f144754 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ SQLA_REPO = {env:SQLA_REPO:git+https://github.com/sqlalchemy/sqlalchemy.git} [testenv] cov_args=--cov=alembic --cov-report term --cov-report xml -deps=pytest!=3.9.1,!=3.9.2 +deps=pytest>4.6 pytest-xdist mock sqla11: {[tox]SQLA_REPO}@rel_1_1 @@ -30,7 +30,7 @@ usedevelop= # only use --dropfirst option if we're *not* using -n; # if -n is used, we're working in brand new DBs anyway setenv= - BASECOMMAND=python -m pytest + BASECOMMAND=python -m pytest --rootdir {toxinidir} WORKERS=-n4 sqla079: WORKERS=--dropfirst cov: COVERAGE={[testenv]cov_args}