Compare commits

...

15 Commits
1.3 ... 1.4

Author SHA1 Message Date
holger krekel
feaf840fab just use the released version fo execnet 2010-07-07 18:33:27 +02:00
holger krekel
f112ad6cfb typo 2010-07-07 18:14:28 +02:00
holger krekel
71771fbdc6 improved versioing 2010-07-07 18:12:43 +02:00
holger krekel
c0b2df1a77 show detailed gateway setup info only with "--verbose" or "-v" 2010-07-07 16:44:12 +02:00
holger krekel
9aa1df89ee bump to xdist 1.4 2010-07-07 14:52:40 +02:00
holger krekel
67e0cd463c add a test created from jgustak (but add the related env feature to execnet where it
is separately tested)
2010-07-07 14:33:24 +02:00
holger krekel
fb31aa882d integrate xdist related reporting into the plugin 2010-07-07 12:43:19 +02:00
holger krekel
51b0ba55e9 don't test deprecation warnings on python2.7 2010-07-06 15:01:40 +02:00
holger krekel
d0ccb5743d refining tests for jython and python2.7 2010-07-06 13:50:03 +02:00
holger krekel
fa7da18d9b using proper distshare dir for hudson 2010-07-06 12:56:15 +02:00
holger krekel
cf36bf8bf2 bumping version 2010-07-06 12:51:09 +02:00
holger krekel
55e3d27820 adding a tox.ini file 2010-07-06 12:50:06 +02:00
holger krekel
a17bc05c5a merge 2010-06-27 14:00:01 +02:00
holger krekel
e5e23fd278 add a test for issue57 which currently needs to be fixed on py-trunk though 2010-05-26 18:52:58 +02:00
holger krekel
e48dcda834 Added tag 1.3 for changeset eaf8b1cb7c31 2010-05-25 21:23:29 +02:00
15 changed files with 246 additions and 18 deletions

View File

@@ -19,3 +19,4 @@ dist/
pytest_xdist.egg-info
issue/
3rdparty/
.tox

View File

@@ -2,3 +2,5 @@
eca7ce17eabf296983c36812c8b8be901e7055a3 1.1
56d8e5280be224a0ad3220a9deed55334710bd23 1.2
e6c4ce20db4bf65086ff55807a3c306cad7ca393 1.3
e6c4ce20db4bf65086ff55807a3c306cad7ca393 1.3
eaf8b1cb7c312883598677231be5bbeea3b5c127 1.3

View File

@@ -1,3 +1,16 @@
1.4
-------------------------
- perform distributed testing related reporting in the plugin
rather than having dist-related code in the generic py.test
distribution
- depend on execnet-1.0.7 which adds "env1:NAME=value" keys to
gateway specification strings.
- show detailed gateway setup and platform information only when
"-v" or "--verbose" is specified.
1.3
-------------------------

View File

@@ -22,7 +22,7 @@ setup(
packages = ['xdist'],
entry_points = {'pytest11': ['xdist = xdist.plugin'],},
zip_safe=False,
install_requires = ['execnet>=1.0.6', 'py>=1.3.1'],
install_requires = ['execnet>=1.0.7', 'py>1.3.1'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',

View File

@@ -1,4 +1,5 @@
import py
import sys
class TestDistribution:
def test_manytests_to_one_popen(self, testdir):
@@ -14,7 +15,7 @@ class TestDistribution:
py.test.skip("hello")
""",
)
result = testdir.runpytest(p1, '-d', '--tx=popen', '--tx=popen')
result = testdir.runpytest(p1, "-v", '-d', '--tx=popen', '--tx=popen')
result.stdout.fnmatch_lines([
"*0*popen*Python*",
"*1*popen*Python*",
@@ -38,7 +39,7 @@ class TestDistribution:
testdir.makeconftest("""
option_tx = 'popen popen popen'.split()
""")
result = testdir.runpytest(p1, '-d')
result = testdir.runpytest(p1, '-d', "-v")
result.stdout.fnmatch_lines([
"*0*popen*Python*",
"*1*popen*Python*",
@@ -47,6 +48,7 @@ class TestDistribution:
])
assert result.ret == 1
@py.test.mark.xfail("sys.platform.startswith('java')")
def test_dist_tests_with_crash(self, testdir):
if not hasattr(py.std.os, 'kill'):
py.test.skip("no os.kill")
@@ -68,7 +70,7 @@ class TestDistribution:
os.kill(os.getpid(), 15)
"""
)
result = testdir.runpytest(p1, '-d', '--tx=3*popen')
result = testdir.runpytest(p1, "-v", '-d', '--tx=3*popen')
result.stdout.fnmatch_lines([
"*popen*Python*",
"*popen*Python*",
@@ -85,7 +87,7 @@ class TestDistribution:
subdir.ensure("__init__.py")
p = subdir.join("test_one.py")
p.write("def test_5(): assert not __file__.startswith(%r)" % str(p))
result = testdir.runpytest("-d", "--rsyncdir=%(subdir)s" % locals(),
result = testdir.runpytest("-v", "-d", "--rsyncdir=%(subdir)s" % locals(),
"--tx=popen//chdir=%(dest)s" % locals(), p)
assert result.ret == 0
result.stdout.fnmatch_lines([
@@ -110,7 +112,7 @@ class TestDistribution:
print("%s...%s" % sys.version_info[:2])
assert 0
""")
args = ["--dist=each"]
args = ["--dist=each", "-v"]
args += ["--tx", "popen//python=%s" % interpreters[0]]
args += ["--tx", "popen//python=%s" % interpreters[1]]
result = testdir.runpytest(*args)
@@ -145,7 +147,7 @@ class TestDistribution:
'calculated result is %s' % calc_result)
""")
p1 = testdir.makepyfile("def test_func(): pass")
result = testdir.runpytest(p1, '-d', '--tx=popen')
result = testdir.runpytest("-v", p1, '-d', '--tx=popen')
result.stdout.fnmatch_lines([
"*popen*Python*",
"*calculated result is 49*",
@@ -172,3 +174,57 @@ class TestDistribution:
assert result.ret
assert 'SIGINT' in s
assert 's2call' in s
def test_keyboard_interrupt_dist(self, testdir):
# xxx could be refined to check for return code
p = testdir.makepyfile("""
def test_sleep():
import time
time.sleep(10)
""")
child = testdir.spawn_pytest("-n1")
child.expect(".*test session starts.*")
child.kill(2) # keyboard interrupt
child.expect(".*KeyboardInterrupt.*")
#child.expect(".*seconds.*")
child.close()
#assert ret == 2
class TestTerminalReporting:
def test_pass_skip_fail(self, testdir):
p = testdir.makepyfile("""
import py
def test_ok():
pass
def test_skip():
py.test.skip("xx")
def test_func():
assert 0
""")
result = testdir.runpytest("-n1", "-v")
expected = [
"*PASS*test_pass_skip_fail.py:2: *test_ok*",
"*SKIP*test_pass_skip_fail.py:4: *test_skip*",
"*FAIL*test_pass_skip_fail.py:6: *test_func*",
]
for line in expected:
result.stdout.fnmatch_lines([line])
result.stdout.fnmatch_lines([
" def test_func():",
"> assert 0",
"E assert 0",
])
def test_fail_platinfo(self, testdir):
p = testdir.makepyfile("""
def test_func():
assert 0
""")
result = testdir.runpytest("-n1", "-v")
result.stdout.fnmatch_lines([
"*FAIL*test_fail_platinfo.py:1: *test_func*",
"*popen*Python*",
" def test_func():",
"> assert 0",
"E assert 0",
])

View File

@@ -2,7 +2,6 @@ import py
import execnet
pytest_plugins = "pytester"
option_report = 'skipped'
#rsyncdirs = ['.', '../xdist', py.path.local(execnet.__file__).dirpath()]

View File

@@ -1,6 +1,7 @@
import py
def test_dist_conftest_options(testdir):
@py.test.mark.xfail("sys.version_info[:2] == (2,7)")
def test_dist_conftest_options(testdir, recwarn):
p1 = testdir.tmpdir.ensure("dir", 'p1.py')
p1.dirpath("__init__.py").write("")
p1.dirpath("conftest.py").write(py.code.Source("""

View File

@@ -132,7 +132,7 @@ class TestLooponFailing:
x = 0
assert x == 1
""")
child = testdir.spawn_pytest("-f %s" % p)
child = testdir.spawn_pytest("-f %s --traceconfig" % p)
child.expect("def test_one")
child.expect("x == 1")
child.expect("1 failed")
@@ -146,3 +146,16 @@ class TestLooponFailing:
child.expect(".*1 passed.*")
child.kill(15)
def test_looponfail_xfail_passes(self, testdir):
p = testdir.makepyfile("""
import py
@py.test.mark.xfail
def test_one():
pass
""")
child = testdir.spawn_pytest("-f %s" % p)
child.expect("1 xpass")
child.expect("### LOOPONFAILING ####")
child.expect("waiting for changes")
child.kill(15)

View File

@@ -42,13 +42,13 @@ class MySetup:
eq = EventQueue(self.config.pluginmanager, self.queue)
return eq.geteventargs(eventname, timeout=timeout)
def makenode(self, config=None):
def makenode(self, config=None, xspec="popen"):
if config is None:
testdir = self.request.getfuncargvalue("testdir")
config = testdir.reparseconfig([])
self.config = config
self.queue = Queue()
self.xspec = execnet.XSpec("popen")
self.xspec = execnet.XSpec(xspec)
self.gateway = execnet.makegateway(self.xspec)
self.id += 1
self.gateway.id = str(self.id)
@@ -147,3 +147,26 @@ class TestMasterSlaveConnection:
for outcome in "passed failed skipped".split():
rep = mysetup.geteventargs("pytest_runtest_logreport")['report']
assert getattr(rep, outcome)
def test_send_one_with_env(self, testdir, mysetup, monkeypatch):
if execnet.XSpec("popen").env is None:
py.test.skip("requires execnet 1.0.7 or above")
monkeypatch.delenv('ENV1', raising=False)
monkeypatch.delenv('ENV2', raising=False)
monkeypatch.setenv('ENV3', 'var3')
item = testdir.getitem("""
def test_func():
import os
# ENV1, ENV2 set by xspec; ENV3 inherited from parent process
assert os.getenv('ENV2') == 'var2'
assert os.getenv('ENV1') == 'var1'
assert os.getenv('ENV3') == 'var3'
""")
node = mysetup.makenode(item.config,
xspec="popen//env:ENV1=var1//env:ENV2=var2")
node.send(item)
kwargs = mysetup.geteventargs("pytest_runtest_logreport")
rep = kwargs['report']
assert rep.passed

35
tox.ini Normal file
View File

@@ -0,0 +1,35 @@
[tox]
distshare={homedir}/.tox/distshare
envlist=py26,py31,py27,py25,py24
[tox:hudson]
distshare={toxworkdir}/distshare
sdistsrc={distshare}/pytest-xdist-*
[testenv]
changedir=testing
deps=
{distshare}/py-*
commands=
py.test -rsfxX --tools-on-path \
--junitxml={envlogdir}/junit-{envname}.xml []
[testenv:py27]
basepython=python2.7
[testenv:py26]
basepython=python2.6
deps=
{distshare}/py-*
pexpect
#[testenv:py26-py132]
#basepython=python2.6
#deps= py==1.3.2
# execnet==1.0.6
[testenv:py25]
basepython=python2.5
[testenv:py24]
basepython=python2.4
[testenv:py31]
basepython=python3.1
#[testenv:pypy]
#basepython=pypy-c
[testenv:jython]
basepython=jython

View File

@@ -1,3 +1,3 @@
#
__version__ = "1.3"
__version__ = "1.4"

View File

@@ -100,9 +100,12 @@ class DSession(session.Session):
return exitstatus
def collect_all_items(self, colitems):
self.report_line("[master] starting full item collection ...")
verbose = self.config.getvalue("verbose")
if verbose:
self.report_line("[master] starting full item collection ...")
allitems = list(self.collect(colitems))
self.report_line("[master] collected %d items" %(len(allitems)))
if verbose:
self.report_line("[master] collected %d items" %(len(allitems)))
return allitems
def loop_once(self, loopstate):
@@ -286,6 +289,9 @@ class DSession(session.Session):
def setup(self):
""" setup any neccessary resources ahead of the test run. """
if not self.config.getvalue("verbose"):
self.report_line("instantiating gateways (use -v for details): %s" %
",".join(self.config.option.tx))
self.nodemanager = NodeManager(self.config)
self.nodemanager.setup_nodes(putevent=self.queue.put)

View File

@@ -20,6 +20,4 @@ def pytest_testnodedown(node, error):
def pytest_rescheduleitems(items):
""" reschedule Items from a node that went down. """
def pytest_looponfailinfo(failreports, rootdirs):
""" info for repeating failing tests. """

View File

@@ -197,11 +197,23 @@ def pytest_configure(config):
raise config.Error("--pdb incompatible with --looponfail.")
from xdist.remote import LooponfailingSession
config.setsessionclass(LooponfailingSession)
config._isdistsession = True
elif val("dist") != "no":
if usepdb:
raise config.Error("--pdb incompatible with distributing tests.")
from xdist.dsession import DSession
config.setsessionclass(DSession)
config._isdistsession = True
def pytest_sessionstart(session):
config = session.config
if hasattr(config, '_isdistsession'):
if not config.pluginmanager.hasplugin("terminal") or \
not config.pluginmanager.hasplugin("terminalreporter"):
return
trdist = TerminalDistReporter(config)
config.pluginmanager.register(trdist, "terminaldistreporter")
def pytest_runtest_protocol(item):
if item.config.getvalue("boxed"):
@@ -244,3 +256,59 @@ def report_process_crash(item, result):
from py._plugin.pytest_runner import ItemTestReport
return ItemTestReport(item, excinfo=info, when="???")
class TerminalDistReporter:
def __init__(self, config):
self.gateway2info = {}
self.config = config
self.tplugin = config.pluginmanager.getplugin("terminal")
self.tr = config.pluginmanager.getplugin("terminalreporter")
def write_line(self, msg):
self.tr.write_line(msg)
def pytest_itemstart(self, __multicall__):
try:
__multicall__.methods.remove(self.tr.pytest_itemstart)
except KeyError:
pass
def pytest_runtest_logreport(self, report):
if hasattr(report, 'node'):
report.headerlines.append(self.gateway2info.get(
report.node.gateway,
"node %r (platinfo not found? strange)"))
def pytest_gwmanage_newgateway(self, gateway, platinfo):
#self.write_line("%s instantiated gateway from spec %r" %(gateway.id, gateway.spec._spec))
d = {}
d['version'] = self.tplugin.repr_pythonversion(platinfo.version_info)
d['id'] = gateway.id
d['spec'] = gateway.spec._spec
d['platform'] = platinfo.platform
if self.config.option.verbose:
d['extra'] = "- " + platinfo.executable
else:
d['extra'] = ""
d['cwd'] = platinfo.cwd
infoline = ("[%(id)s] %(spec)s -- platform %(platform)s, "
"Python %(version)s "
"cwd: %(cwd)s"
"%(extra)s" % d)
if self.config.getvalue("verbose"):
self.write_line(infoline)
self.gateway2info[gateway] = infoline
def pytest_testnodeready(self, node):
if self.config.getvalue("verbose"):
self.write_line(
"[%s] txnode ready to receive tests" %(node.gateway.id,))
def pytest_testnodedown(self, node, error):
if not error:
return
self.write_line("[%s] node down, error: %s" %(node.gateway.id, error))
def pytest_rescheduleitems(self, items):
if self.config.option.debug:
self.write_sep("!", "RESCHEDULING %s " %(items,))

View File

@@ -169,8 +169,21 @@ def slave_runsession(channel, config, fullwidth, hasmarkup):
DEBUG("SLAVE: starting session.main()")
session.main(colitems)
session.config.hook.pytest_looponfailinfo(
repr_pytest_looponfailinfo(
failreports=list(failreports),
rootdirs=[config.topdir])
rootcol = session.config._rootcol
channel.send([rootcol.totrail(rep.getnode()) for rep in failreports])
def repr_pytest_looponfailinfo(failreports, rootdirs):
tr = py.io.TerminalWriter()
if failreports:
tr.sep("#", "LOOPONFAILING", red=True)
for report in failreports:
loc = report._getcrashline()
if loc:
tr.line(loc, red=True)
tr.sep("#", "waiting for changes")
for rootdir in rootdirs:
tr.line("### Watching: %s" %(rootdir,), bold=True)