diff options
author | Brian Jarrett <celttechie@gmail.com> | 2014-07-20 12:44:40 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-20 12:44:40 -0400 |
commit | cca03097f47f22783d42d1853faac6cf84607c5a (patch) | |
tree | 4fe1a63d03a2d88d1cf37e1167759dfaf84f4ce7 /lib/sqlalchemy/testing/plugin/pytestplugin.py | |
parent | 827329a0cca5351094a1a86b6b2be2b9182f0ae2 (diff) | |
download | sqlalchemy-cca03097f47f22783d42d1853faac6cf84607c5a.tar.gz |
- apply pep8 formatting to sqlalchemy/sql, sqlalchemy/util, sqlalchemy/dialects,
sqlalchemy/orm, sqlalchemy/event, sqlalchemy/testing
Diffstat (limited to 'lib/sqlalchemy/testing/plugin/pytestplugin.py')
-rw-r--r-- | lib/sqlalchemy/testing/plugin/pytestplugin.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index 74d5cc083..11238bbac 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -4,6 +4,7 @@ import inspect from . import plugin_base import collections + def pytest_addoption(parser): group = parser.getgroup("sqlalchemy") @@ -11,7 +12,8 @@ def pytest_addoption(parser): callback_ = kw.pop("callback", None) if callback_: class CallableAction(argparse.Action): - def __call__(self, parser, namespace, values, option_string=None): + def __call__(self, parser, namespace, + values, option_string=None): callback_(option_string, values, parser) kw["action"] = CallableAction @@ -20,10 +22,12 @@ def pytest_addoption(parser): plugin_base.setup_options(make_option) plugin_base.read_config() + def pytest_configure(config): plugin_base.pre_begin(config.option) - plugin_base.set_coverage_flag(bool(getattr(config.option, "cov_source", False))) + plugin_base.set_coverage_flag(bool(getattr(config.option, + "cov_source", False))) plugin_base.post_begin() @@ -42,12 +46,14 @@ def pytest_collection_modifyitems(session, config, items): rebuilt_items = collections.defaultdict(list) test_classes = set(item.parent for item in items) for test_class in test_classes: - for sub_cls in plugin_base.generate_sub_tests(test_class.cls, test_class.parent.module): + for sub_cls in plugin_base.generate_sub_tests( + test_class.cls, test_class.parent.module): if sub_cls is not test_class.cls: list_ = rebuilt_items[test_class.cls] - for inst in pytest.Class(sub_cls.__name__, - parent=test_class.parent.parent).collect(): + for inst in pytest.Class( + sub_cls.__name__, + parent=test_class.parent.parent).collect(): list_.extend(inst.collect()) newitems = [] @@ -61,12 +67,10 @@ def pytest_collection_modifyitems(session, config, items): # 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(newitems, key=lambda item: ( - item.parent.parent.parent.name, - item.parent.parent.name, - item.name - ) - ) - + item.parent.parent.parent.name, + item.parent.parent.name, + item.name + )) def pytest_pycollect_makeitem(collector, name, obj): @@ -82,6 +86,7 @@ def pytest_pycollect_makeitem(collector, name, obj): _current_class = None + def pytest_runtest_setup(item): # here we seem to get called only based on what we collected # in pytest_collection_modifyitems. So to do class-based stuff @@ -100,10 +105,12 @@ def pytest_runtest_setup(item): # this is needed for the class-level, to ensure that the # teardown runs after the class is completed with its own # class-level teardown... - item.parent.parent.addfinalizer(lambda: class_teardown(item.parent.parent)) + item.parent.parent.addfinalizer( + lambda: class_teardown(item.parent.parent)) test_setup(item) + def pytest_runtest_teardown(item): # ...but this works better as the hook here rather than # using a finalizer, as the finalizer seems to get in the way @@ -111,15 +118,19 @@ def pytest_runtest_teardown(item): # py.test assertion stuff instead) test_teardown(item) + def test_setup(item): - plugin_base.before_test(item, - item.parent.module.__name__, item.parent.cls, item.name) + plugin_base.before_test(item, item.parent.module.__name__, + item.parent.cls, item.name) + def test_teardown(item): plugin_base.after_test(item) + def class_setup(item): plugin_base.start_test_class(item.cls) + def class_teardown(item): plugin_base.stop_test_class(item.cls) |