fix issue 93 of pytest - avoid delayed teardowns

This commit is contained in:
holger krekel
2011-12-02 21:03:29 +00:00
parent d5ff8b066a
commit 1f6d410481
9 changed files with 40 additions and 24 deletions

View File

@@ -1,3 +1,9 @@
1.8
-------------------------
- fix pytest-issue93 - use the refined pytest-2.2.1 runtestprotocol
interface to perform eager teardowns for test items.
1.7 1.7
------------------------- -------------------------

View File

@@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name="pytest-xdist", name="pytest-xdist",
version='1.7', version='1.8.dev1',
description='py.test xdist plugin for distributed testing and loop-on-failing modes', description='py.test xdist plugin for distributed testing and loop-on-failing modes',
long_description=open('README.txt').read(), long_description=open('README.txt').read(),
license='GPLv2 or later', license='GPLv2 or later',
@@ -13,7 +13,7 @@ setup(
packages = ['xdist'], packages = ['xdist'],
entry_points = {'pytest11': ['xdist = xdist.plugin'],}, entry_points = {'pytest11': ['xdist = xdist.plugin'],},
zip_safe=False, zip_safe=False,
install_requires = ['execnet>=1.0.8', 'pytest>=2.2.0'], install_requires = ['execnet>=1.0.8', 'pytest>=2.2.1.dev1'],
classifiers=[ classifiers=[
'Development Status :: 5 - Production/Stable', 'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers', 'Intended Audience :: Developers',

View File

@@ -48,11 +48,11 @@ class TestEachScheduling:
assert sched.node2collection[node1] == collection assert sched.node2collection[node1] == collection
assert sched.node2collection[node2] == collection assert sched.node2collection[node2] == collection
sched.init_distribute() sched.init_distribute()
assert not sched.tests_finished() assert sched.tests_finished()
assert node1.sent == ['ALL'] assert node1.sent == ['ALL']
assert node2.sent == ['ALL'] assert node2.sent == ['ALL']
sched.remove_item(node1, collection[0]) sched.remove_item(node1, collection[0])
assert not sched.tests_finished() assert sched.tests_finished()
sched.remove_item(node2, collection[0]) sched.remove_item(node2, collection[0])
assert sched.tests_finished() assert sched.tests_finished()
@@ -66,7 +66,7 @@ class TestEachScheduling:
assert sched.collection_is_completed assert sched.collection_is_completed
assert sched.node2collection[node1] == collection assert sched.node2collection[node1] == collection
sched.init_distribute() sched.init_distribute()
assert not sched.tests_finished() assert sched.tests_finished()
crashitem = sched.remove_node(node1) crashitem = sched.remove_node(node1)
assert crashitem assert crashitem
assert sched.tests_finished() assert sched.tests_finished()
@@ -88,7 +88,7 @@ class TestLoadScheduling:
assert sched.node2collection[node1] == collection assert sched.node2collection[node1] == collection
assert sched.node2collection[node2] == collection assert sched.node2collection[node2] == collection
sched.init_distribute() sched.init_distribute()
assert not sched.tests_finished() assert sched.tests_finished()
assert len(node1.sent) == 1 assert len(node1.sent) == 1
assert len(node2.sent) == 1 assert len(node2.sent) == 1
x = sorted(node1.sent + node2.sent) x = sorted(node1.sent + node2.sent)
@@ -109,6 +109,7 @@ class TestLoadScheduling:
sched.addnode_collection(node1, col) sched.addnode_collection(node1, col)
sched.addnode_collection(node2, col) sched.addnode_collection(node2, col)
sched.init_distribute() sched.init_distribute()
#assert not sched.tests_finished()
sent1 = node1.sent sent1 = node1.sent
sent2 = node2.sent sent2 = node2.sent
chunkitems = col[:sched.ITEM_CHUNKSIZE] chunkitems = col[:sched.ITEM_CHUNKSIZE]

View File

@@ -138,6 +138,7 @@ class TestSlaveInteractor:
ids = ev.kwargs['ids'] ids = ev.kwargs['ids']
assert len(ids) == 1 assert len(ids) == 1
slave.sendcommand("runtests", ids=ids) slave.sendcommand("runtests", ids=ids)
slave.sendcommand("shutdown")
ev = slave.popevent("testreport") # setup ev = slave.popevent("testreport") # setup
ev = slave.popevent("testreport") ev = slave.popevent("testreport")
assert ev.name == "testreport" assert ev.name == "testreport"
@@ -145,7 +146,6 @@ class TestSlaveInteractor:
assert rep.nodeid.endswith("::test_func") assert rep.nodeid.endswith("::test_func")
assert rep.passed assert rep.passed
assert rep.when == "call" assert rep.when == "call"
slave.sendcommand("shutdown")
ev = slave.popevent("slavefinished") ev = slave.popevent("slavefinished")
assert 'slaveoutput' in ev.kwargs assert 'slaveoutput' in ev.kwargs

View File

@@ -21,3 +21,4 @@ deps=
[pytest] [pytest]
addopts = -rsfxX addopts = -rsfxX
;; hello

View File

@@ -1,2 +1,2 @@
# #
__version__ = '1.7' __version__ = '1.8.dev1'

View File

@@ -24,9 +24,6 @@ class EachScheduling:
def tests_finished(self): def tests_finished(self):
if not self.collection_is_completed: if not self.collection_is_completed:
return False return False
for items in self.node2pending.values():
if items:
return False
return True return True
def addnode_collection(self, node, collection): def addnode_collection(self, node, collection):
@@ -79,9 +76,9 @@ class LoadScheduling:
def tests_finished(self): def tests_finished(self):
if not self.collection_is_completed or self.pending: if not self.collection_is_completed or self.pending:
return False return False
for items in self.node2pending.values(): #for items in self.node2pending.values():
if items: # if items:
return False # return False
return True return True
def addnode_collection(self, node, collection): def addnode_collection(self, node, collection):
@@ -107,7 +104,7 @@ class LoadScheduling:
pending.append(item) pending.append(item)
self.item2nodes.setdefault(item, []).append(node) self.item2nodes.setdefault(item, []).append(node)
node.send_runtest(item) node.send_runtest(item)
#self.log("items waiting for node: %d" %(len(self.pending))) self.log("items waiting for node: %d" %(len(self.pending)))
#self.log("item2pending still executing: %s" %(self.item2nodes,)) #self.log("item2pending still executing: %s" %(self.item2nodes,))
#self.log("node2pending: %s" %(self.node2pending,)) #self.log("node2pending: %s" %(self.node2pending,))

View File

@@ -46,18 +46,26 @@ class SlaveInteractor:
def pytest_runtestloop(self, session): def pytest_runtestloop(self, session):
self.log("entering main loop") self.log("entering main loop")
torun = []
while 1: while 1:
name, kwargs = self.channel.receive() name, kwargs = self.channel.receive()
self.log("received command %s(**%s)" % (name, kwargs)) self.log("received command %s(**%s)" % (name, kwargs))
if name == "runtests": if name == "runtests":
ids = kwargs['ids'] ids = kwargs['ids']
for nodeid in ids: for nodeid in ids:
item = self._id2item[nodeid] torun.append(self._id2item[nodeid])
self.config.hook.pytest_runtest_protocol(item=item)
elif name == "runtests_all": elif name == "runtests_all":
for item in session.items: torun.extend(session.items)
self.config.hook.pytest_runtest_protocol(item=item) self.log("items to run: %s" %(len(torun)))
elif name == "shutdown": while len(torun) >= 2:
item = torun.pop(0)
nextitem = torun[0]
self.config.hook.pytest_runtest_protocol(item=item,
nextitem=nextitem)
if name == "shutdown":
while torun:
self.config.hook.pytest_runtest_protocol(
item=torun.pop(0), nextitem=None)
break break
return True return True

View File

@@ -237,8 +237,11 @@ class SlaveController(object):
self.sendcommand("runtests_all",) self.sendcommand("runtests_all",)
def shutdown(self): def shutdown(self):
if not self._down and not self.channel.isclosed(): if not self._down:
self.sendcommand("shutdown") try:
self.sendcommand("shutdown")
except IOError:
pass
def sendcommand(self, name, **kwargs): def sendcommand(self, name, **kwargs):
""" send a named parametrized command to the other side. """ """ send a named parametrized command to the other side. """