diff options
Diffstat (limited to 'lib/sqlalchemy/testing/plugin')
| -rw-r--r-- | lib/sqlalchemy/testing/plugin/bootstrap.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/plugin/pytestplugin.py | 43 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py | 112 |
3 files changed, 5 insertions, 154 deletions
diff --git a/lib/sqlalchemy/testing/plugin/bootstrap.py b/lib/sqlalchemy/testing/plugin/bootstrap.py index b4691c57d..1220561e8 100644 --- a/lib/sqlalchemy/testing/plugin/bootstrap.py +++ b/lib/sqlalchemy/testing/plugin/bootstrap.py @@ -41,10 +41,6 @@ def load_file_as_module(name): if to_bootstrap == "pytest": sys.modules["sqla_plugin_base"] = load_file_as_module("plugin_base") sys.modules["sqla_plugin_base"].bootstrapped_as_sqlalchemy = True - if sys.version_info < (3, 0): - sys.modules["sqla_reinvent_fixtures"] = load_file_as_module( - "reinvent_fixtures_py2k" - ) sys.modules["sqla_pytestplugin"] = load_file_as_module("pytestplugin") else: raise Exception("unknown bootstrap: %s" % to_bootstrap) # noqa diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index 6c6287060..36aaa5d2a 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -25,14 +25,6 @@ except ImportError: has_xdist = False -py2k = sys.version_info < (3, 0) -if py2k: - try: - import sqla_reinvent_fixtures as reinvent_fixtures_py2k - except ImportError: - from . import reinvent_fixtures_py2k - - def pytest_addoption(parser): group = parser.getgroup("sqlalchemy") @@ -238,10 +230,6 @@ def pytest_collection_modifyitems(session, config, items): else: newitems.append(item) - if py2k: - for item in newitems: - reinvent_fixtures_py2k.scan_for_fixtures_to_use_for_class(item) - # seems like the functions attached to a test class aren't sorted already? # is that true and why's that? (when using unittest, they're sorted) items[:] = sorted( @@ -340,9 +328,7 @@ def _parametrize_cls(module, cls): for arg, val in zip(argname_split, param.values): cls_variables[arg] = val parametrized_name = "_".join( - # token is a string, but in py2k pytest is giving us a unicode, - # so call str() on it. - str(re.sub(r"\W", "", token)) + re.sub(r"\W", "", token) for param in full_param_set for token in param.id.split("-") ) @@ -457,14 +443,8 @@ def setup_class_methods(request): if hasattr(cls, "setup_test_class"): asyncio._maybe_async(cls.setup_test_class) - if py2k: - reinvent_fixtures_py2k.run_class_fixture_setup(request) - yield - if py2k: - reinvent_fixtures_py2k.run_class_fixture_teardown(request) - if hasattr(cls, "teardown_test_class"): asyncio._maybe_async(cls.teardown_test_class) @@ -484,9 +464,7 @@ def setup_test_methods(request): # 1. function level "autouse" fixtures under py3k (examples: TablesTest # define tables / data, MappedTest define tables / mappers / data) - # 2. run homegrown function level "autouse" fixtures under py2k - if py2k: - reinvent_fixtures_py2k.run_fn_fixture_setup(request) + # 2. was for p2k. no longer applies # 3. run outer xdist-style setup if hasattr(self, "setup_test"): @@ -529,9 +507,7 @@ def setup_test_methods(request): if hasattr(self, "teardown_test"): asyncio._maybe_async(self.teardown_test) - # 11. run homegrown function-level "autouse" fixtures under py2k - if py2k: - reinvent_fixtures_py2k.run_fn_fixture_teardown(request) + # 11. was for p2k. no longer applies # 12. function level "autouse" fixtures under py3k (examples: TablesTest / # MappedTest delete table data, possibly drop tables and clear mappers @@ -778,17 +754,8 @@ class PytestFixtureFunctions(plugin_base.FixtureFunctions): fn = asyncio._maybe_async_wrapper(fn) # other wrappers may be added here - if py2k and "autouse" in kw: - # py2k workaround for too-slow collection of autouse fixtures - # in pytest 4.6.11. See notes in reinvent_fixtures_py2k for - # rationale. - - # comment this condition out in order to disable the - # py2k workaround entirely. - reinvent_fixtures_py2k.add_fixture(fn, fixture) - else: - # now apply FixtureFunctionMarker - fn = fixture(fn) + # now apply FixtureFunctionMarker + fn = fixture(fn) return fn diff --git a/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py b/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py deleted file mode 100644 index 36b68417b..000000000 --- a/lib/sqlalchemy/testing/plugin/reinvent_fixtures_py2k.py +++ /dev/null @@ -1,112 +0,0 @@ -""" -invent a quick version of pytest autouse fixtures as pytest's unacceptably slow -collection/high memory use in pytest 4.6.11, which is the highest version that -works in py2k. - -by "too-slow" we mean the test suite can't even manage to be collected for a -single process in less than 70 seconds or so and memory use seems to be very -high as well. for two or four workers the job just times out after ten -minutes. - -so instead we have invented a very limited form of these fixtures, as our -current use of "autouse" fixtures are limited to those in fixtures.py. - -assumptions for these fixtures: - -1. we are only using "function" or "class" scope - -2. the functions must be associated with a test class - -3. the fixture functions cannot themselves use pytest fixtures - -4. the fixture functions must use yield, not return - -When py2k support is removed and we can stay on a modern pytest version, this -can all be removed. - - -""" -import collections - - -_py2k_fixture_fn_names = collections.defaultdict(set) -_py2k_class_fixtures = collections.defaultdict( - lambda: collections.defaultdict(set) -) -_py2k_function_fixtures = collections.defaultdict( - lambda: collections.defaultdict(set) -) - -_py2k_cls_fixture_stack = [] -_py2k_fn_fixture_stack = [] - - -def add_fixture(fn, fixture): - assert fixture.scope in ("class", "function") - _py2k_fixture_fn_names[fn.__name__].add((fn, fixture.scope)) - - -def scan_for_fixtures_to_use_for_class(item): - test_class = item.parent.parent.obj - - for name in _py2k_fixture_fn_names: - for fixture_fn, scope in _py2k_fixture_fn_names[name]: - meth = getattr(test_class, name, None) - if meth and meth.im_func is fixture_fn: - for sup in test_class.__mro__: - if name in sup.__dict__: - if scope == "class": - _py2k_class_fixtures[test_class][sup].add(meth) - elif scope == "function": - _py2k_function_fixtures[test_class][sup].add(meth) - break - break - - -def run_class_fixture_setup(request): - - cls = request.cls - self = cls.__new__(cls) - - fixtures_for_this_class = _py2k_class_fixtures.get(cls) - - if fixtures_for_this_class: - for sup_ in cls.__mro__: - for fn in fixtures_for_this_class.get(sup_, ()): - iter_ = fn(self) - next(iter_) - - _py2k_cls_fixture_stack.append(iter_) - - -def run_class_fixture_teardown(request): - while _py2k_cls_fixture_stack: - iter_ = _py2k_cls_fixture_stack.pop(-1) - try: - next(iter_) - except StopIteration: - pass - - -def run_fn_fixture_setup(request): - cls = request.cls - self = request.instance - - fixtures_for_this_class = _py2k_function_fixtures.get(cls) - - if fixtures_for_this_class: - for sup_ in reversed(cls.__mro__): - for fn in fixtures_for_this_class.get(sup_, ()): - iter_ = fn(self) - next(iter_) - - _py2k_fn_fixture_stack.append(iter_) - - -def run_fn_fixture_teardown(request): - while _py2k_fn_fixture_stack: - iter_ = _py2k_fn_fixture_stack.pop(-1) - try: - next(iter_) - except StopIteration: - pass |
