From 17fbae067df9beec8bc9ec76a35598554a877623 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 1 Nov 2016 20:24:04 +0000 Subject: [PATCH] Make sure the pytester plugin is called. In the new model of gathering tests, the pytester plugin which ensures that fixtures are started and stopped but not counted as tests was not being run because test-name matching was no longer working correctly. These changes ensure that the plugin is run. Despite the small change here, this took absolute ages to get right. And it still doesn't fix the problem present in the previous commit: The need for the test_pytest function to be present in the namespace of the test module. So a few more iterations remain. --- gabbi/driver.py | 6 +++--- gabbi/pytester.py | 30 +++++++++++++----------------- gabbi/tests/test_gabbits_pytest.py | 4 ++-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/gabbi/driver.py b/gabbi/driver.py index 8220bf5..af0dd3e 100644 --- a/gabbi/driver.py +++ b/gabbi/driver.py @@ -170,7 +170,7 @@ def py_test_generator(test_dir, host=None, port=8001, intercept=None, ids = [] args = [] for test in test_list: - if len(test) >=3: + if len(test) >= 3: name, method, arg = test else: name, method = test @@ -185,9 +185,9 @@ def py_test_generator(test_dir, host=None, port=8001, intercept=None, def test_pytest(test, result): - try: + if result: test(result) - except TypeError: + else: test() diff --git a/gabbi/pytester.py b/gabbi/pytester.py index bf432d3..7df4771 100644 --- a/gabbi/pytester.py +++ b/gabbi/pytester.py @@ -30,9 +30,11 @@ STOPS = {} def get_cleanname(item): """Extract a test name from a pytest Function item.""" - cleanname = item.name[2:] - cleanname = cleanname[:-2] - return cleanname + if '[' in item.name: + cleanname = item.name.split('[', 1)[1] + cleanname = cleanname.split(']', 1)[0] + return cleanname + return item.name def get_suitename(name): @@ -86,10 +88,13 @@ def a_pytest_collection_modifyitems(items, config): continue suitename = get_suitename(cleanname) if cleanname.startswith('start_'): - STARTS[suitename] = item + test = item.callspec.params['test'] + result = item.callspec.params['result'] + STARTS[suitename] = (test, result) deselected.append(item) elif cleanname.startswith('stop_'): - STOPS[suitename] = item + test = item.callspec.params['test'] + STOPS[suitename] = test deselected.append(item) else: remaining.append(item) @@ -118,20 +123,11 @@ def pytest_runtest_setup(item): run its priors after running this. """ if hasattr(item, 'starter'): - try: - # Python 2 - item.starter.function(item.starter.obj.__self__, item._args[0]) - except TypeError: - # Python 3 - item.starter.function(item._args[0]) + test, result = item.starter + test(result) def pytest_runtest_teardown(item, nextitem): """Run a stopper if a test has one.""" if hasattr(item, 'stopper'): - try: - # Python 2 - item.stopper.function(item.stopper.obj.__self__) - except TypeError: - # Python 3 - item.stopper.function() + item.stopper() diff --git a/gabbi/tests/test_gabbits_pytest.py b/gabbi/tests/test_gabbits_pytest.py index 739cddd..ef25b55 100644 --- a/gabbi/tests/test_gabbits_pytest.py +++ b/gabbi/tests/test_gabbits_pytest.py @@ -19,9 +19,9 @@ without duplication. import os -# TODO: this test_* needs to be imported bare or things do not work -from gabbi.driver import test_pytest from gabbi import driver +# TODO(cdent): this test_* needs to be imported bare or things do not work +from gabbi.driver import test_pytest # noqa from gabbi.tests import simple_wsgi from gabbi.tests import test_intercept