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

View File

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

View File

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

View File

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

View File

@@ -21,3 +21,4 @@ deps=
[pytest]
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):
if not self.collection_is_completed:
return False
for items in self.node2pending.values():
if items:
return False
return True
def addnode_collection(self, node, collection):
@@ -79,9 +76,9 @@ class LoadScheduling:
def tests_finished(self):
if not self.collection_is_completed or self.pending:
return False
for items in self.node2pending.values():
if items:
return False
#for items in self.node2pending.values():
# if items:
# return False
return True
def addnode_collection(self, node, collection):
@@ -107,7 +104,7 @@ class LoadScheduling:
pending.append(item)
self.item2nodes.setdefault(item, []).append(node)
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("node2pending: %s" %(self.node2pending,))

View File

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

View File

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