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.
This commit is contained in:
Chris Dent 2016-11-01 20:24:04 +00:00
parent 439706c464
commit 17fbae067d
3 changed files with 18 additions and 22 deletions

View File

@ -170,7 +170,7 @@ def py_test_generator(test_dir, host=None, port=8001, intercept=None,
ids = [] ids = []
args = [] args = []
for test in test_list: for test in test_list:
if len(test) >=3: if len(test) >= 3:
name, method, arg = test name, method, arg = test
else: else:
name, method = test name, method = test
@ -185,9 +185,9 @@ def py_test_generator(test_dir, host=None, port=8001, intercept=None,
def test_pytest(test, result): def test_pytest(test, result):
try: if result:
test(result) test(result)
except TypeError: else:
test() test()

View File

@ -30,9 +30,11 @@ STOPS = {}
def get_cleanname(item): def get_cleanname(item):
"""Extract a test name from a pytest Function item.""" """Extract a test name from a pytest Function item."""
cleanname = item.name[2:] if '[' in item.name:
cleanname = cleanname[:-2] cleanname = item.name.split('[', 1)[1]
return cleanname cleanname = cleanname.split(']', 1)[0]
return cleanname
return item.name
def get_suitename(name): def get_suitename(name):
@ -86,10 +88,13 @@ def a_pytest_collection_modifyitems(items, config):
continue continue
suitename = get_suitename(cleanname) suitename = get_suitename(cleanname)
if cleanname.startswith('start_'): if cleanname.startswith('start_'):
STARTS[suitename] = item test = item.callspec.params['test']
result = item.callspec.params['result']
STARTS[suitename] = (test, result)
deselected.append(item) deselected.append(item)
elif cleanname.startswith('stop_'): elif cleanname.startswith('stop_'):
STOPS[suitename] = item test = item.callspec.params['test']
STOPS[suitename] = test
deselected.append(item) deselected.append(item)
else: else:
remaining.append(item) remaining.append(item)
@ -118,20 +123,11 @@ def pytest_runtest_setup(item):
run its priors after running this. run its priors after running this.
""" """
if hasattr(item, 'starter'): if hasattr(item, 'starter'):
try: test, result = item.starter
# Python 2 test(result)
item.starter.function(item.starter.obj.__self__, item._args[0])
except TypeError:
# Python 3
item.starter.function(item._args[0])
def pytest_runtest_teardown(item, nextitem): def pytest_runtest_teardown(item, nextitem):
"""Run a stopper if a test has one.""" """Run a stopper if a test has one."""
if hasattr(item, 'stopper'): if hasattr(item, 'stopper'):
try: item.stopper()
# Python 2
item.stopper.function(item.stopper.obj.__self__)
except TypeError:
# Python 3
item.stopper.function()

View File

@ -19,9 +19,9 @@ without duplication.
import os 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 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 simple_wsgi
from gabbi.tests import test_intercept from gabbi.tests import test_intercept