diff options
| author | Gord Thompson <gord@gordthompson.com> | 2021-08-12 13:04:28 -0600 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-09-30 10:10:16 -0400 |
| commit | 257f9130c321aaa948690d0e49c7352ad1188abd (patch) | |
| tree | 2648c88460c3e5de847ee998edb7a6df0aa9b261 /lib/sqlalchemy/testing | |
| parent | f7f2df607301afcd11dd49a2ccb632291de12d29 (diff) | |
| download | sqlalchemy-257f9130c321aaa948690d0e49c7352ad1188abd.tar.gz | |
Modernize tests - calling_mapper_directly
a few changes for py2k:
* map_imperatively() includes the check that a class
is being sent, this was only working for mapper() before
* the test suite didn't place the py2k "autouse" workaround
in the correct order, seemingly, tried to adjust the
per-test ordering setup in pytestplugin.py
Change-Id: I4cc39630724e810953cfda7b2afdadc8b948e3c2
Diffstat (limited to 'lib/sqlalchemy/testing')
| -rw-r--r-- | lib/sqlalchemy/testing/fixtures.py | 15 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/plugin/pytestplugin.py | 47 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/warnings.py | 5 |
3 files changed, 34 insertions, 33 deletions
diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index 01a838c56..f04056c5e 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -638,12 +638,17 @@ class MappedTest(TablesTest, assertions.AssertsExecutionResults): @classmethod def _setup_once_mappers(cls): if cls.run_setup_mappers == "once": - cls.mapper = cls._generate_mapper() + cls.mapper_registry, cls.mapper = cls._generate_registry() cls._with_register_classes(cls.setup_mappers) def _setup_each_mappers(self): + if self.run_setup_mappers != "once": + ( + self.__class__.mapper_registry, + self.__class__.mapper, + ) = self._generate_registry() + if self.run_setup_mappers == "each": - self.__class__.mapper = self._generate_mapper() self._with_register_classes(self.setup_mappers) def _setup_each_classes(self): @@ -651,9 +656,9 @@ class MappedTest(TablesTest, assertions.AssertsExecutionResults): self._with_register_classes(self.setup_classes) @classmethod - def _generate_mapper(cls): - decl = registry() - return decl.map_imperatively + def _generate_registry(cls): + decl = registry(metadata=cls._tables_metadata) + return decl, decl.map_imperatively @classmethod def _with_register_classes(cls, fn): diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index d28048f70..6c6287060 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -479,7 +479,16 @@ def setup_test_methods(request): self = request.instance - # 1. run outer xdist-style setup + # before this fixture runs: + + # 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) + + # 3. run outer xdist-style setup if hasattr(self, "setup_test"): asyncio._maybe_async(self.setup_test) @@ -489,15 +498,7 @@ def setup_test_methods(request): if hasattr(self, "setUp"): asyncio._maybe_async(self.setUp) - # 2. run homegrown function level "autouse" fixtures under py2k - if py2k: - reinvent_fixtures_py2k.run_fn_fixture_setup(request) - # inside the yield: - - # 3. function level "autouse" fixtures under py3k (examples: TablesTest - # define tables / data, MappedTest define tables / mappers / data) - # 4. function level fixtures defined on test functions themselves, # e.g. "connection", "metadata" run next @@ -509,33 +510,33 @@ def setup_test_methods(request): # yield finishes: - # 7. pytest hook pytest_runtest_teardown hook runs, this is associated + # 7. function level fixtures defined on test functions + # themselves, e.g. "connection" rolls back the transaction, "metadata" + # emits drop all + + # 8. pytest hook pytest_runtest_teardown hook runs, this is associated # with fixtures close all sessions, provisioning.stop_test_class(), # engines.testing_reaper -> ensure all connection pool connections # are returned, engines created by testing_engine that aren't the # config engine are disposed - # 8. function level fixtures defined on test functions - # themselves, e.g. "connection" rolls back the transaction, "metadata" - # emits drop all - - # 9. function level "autouse" fixtures under py3k (examples: TablesTest / - # MappedTest delete table data, possibly drop tables and clear mappers - # depending on the flags defined by the test class) - - # 10. run homegrown function-level "autouse" fixtures under py2k - if py2k: - reinvent_fixtures_py2k.run_fn_fixture_teardown(request) - asyncio._maybe_async(plugin_base.after_test_fixtures, self) - # 11. run outer xdist-style teardown + # 10. run xdist-style teardown if hasattr(self, "tearDown"): asyncio._maybe_async(self.tearDown) 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) + + # 12. function level "autouse" fixtures under py3k (examples: TablesTest / + # MappedTest delete table data, possibly drop tables and clear mappers + # depending on the flags defined by the test class) + def getargspec(fn): if sys.version_info.major == 3: diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py index f72d53d67..67ed452a0 100644 --- a/lib/sqlalchemy/testing/warnings.py +++ b/lib/sqlalchemy/testing/warnings.py @@ -66,11 +66,6 @@ def setup_filters(): # we are moving one at a time for msg in [ # - # ORM configuration - # - r"Calling the mapper\(\) function directly outside of a " - "declarative registry", - # # ORM Query # r"The Query\.get\(\) method", |
