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

@ -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()

View File

@ -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]
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()

View File

@ -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