2009-10-30 03:10:05 +08:00
|
|
|
import py
|
2009-12-31 00:11:48 +08:00
|
|
|
import sys
|
2009-10-30 03:10:05 +08:00
|
|
|
|
2009-04-08 23:15:56 +08:00
|
|
|
pytest_plugins = '_pytest doctest pytester'.split()
|
|
|
|
|
2009-12-07 02:18:44 +08:00
|
|
|
collect_ignore = ['build', 'doc/_build']
|
|
|
|
|
2009-10-30 03:10:05 +08:00
|
|
|
rsyncdirs = ['conftest.py', 'bin', 'py', 'doc', 'testing']
|
2009-03-19 05:24:42 +08:00
|
|
|
|
2010-05-25 18:24:51 +08:00
|
|
|
import os, py
|
|
|
|
pid = os.getpid()
|
|
|
|
|
2009-05-19 05:26:16 +08:00
|
|
|
def pytest_addoption(parser):
|
2009-10-17 23:43:33 +08:00
|
|
|
group = parser.getgroup("pylib", "py lib testing options")
|
2010-07-27 03:15:15 +08:00
|
|
|
group.addoption('--sshhost',
|
2009-05-19 05:26:16 +08:00
|
|
|
action="store", dest="sshhost", default=None,
|
|
|
|
help=("ssh xspec for ssh functional tests. "))
|
|
|
|
group.addoption('--runslowtests',
|
|
|
|
action="store_true", dest="runslowtests", default=False,
|
|
|
|
help=("run slow tests"))
|
2010-05-25 18:24:51 +08:00
|
|
|
group.addoption('--lsof',
|
|
|
|
action="store_true", dest="lsof", default=False,
|
|
|
|
help=("run FD checks if lsof is available"))
|
|
|
|
|
|
|
|
def pytest_configure(config):
|
|
|
|
if config.getvalue("lsof"):
|
|
|
|
try:
|
|
|
|
out = py.process.cmdexec("lsof -p %d" % pid)
|
|
|
|
except py.process.cmdexec.Error:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
config._numfiles = len([x for x in out.split("\n") if "REG" in x])
|
2009-03-20 23:36:45 +08:00
|
|
|
|
2010-05-25 18:24:51 +08:00
|
|
|
def pytest_unconfigure(config, __multicall__):
|
|
|
|
if not hasattr(config, '_numfiles'):
|
|
|
|
return
|
|
|
|
__multicall__.execute()
|
|
|
|
out2 = py.process.cmdexec("lsof -p %d" % pid)
|
|
|
|
len2 = len([x for x in out2.split("\n") if "REG" in x])
|
|
|
|
assert len2 < config._numfiles + 7, out2
|
2009-07-31 20:21:02 +08:00
|
|
|
|
2010-01-13 23:00:33 +08:00
|
|
|
def pytest_funcarg__sshhost(request):
|
|
|
|
val = request.config.getvalue("sshhost")
|
|
|
|
if val:
|
|
|
|
return val
|
2010-07-27 03:15:15 +08:00
|
|
|
py.test.skip("need --sshhost option")
|
2009-07-31 20:21:02 +08:00
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
multi = getattr(metafunc.function, 'multi', None)
|
2009-12-31 00:11:48 +08:00
|
|
|
if multi is not None:
|
|
|
|
assert len(multi.kwargs) == 1
|
|
|
|
for name, l in multi.kwargs.items():
|
|
|
|
for val in l:
|
|
|
|
metafunc.addcall(funcargs={name: val})
|
|
|
|
elif 'anypython' in metafunc.funcargnames:
|
2010-07-27 03:15:15 +08:00
|
|
|
for name in ('python2.4', 'python2.5', 'python2.6',
|
2009-12-31 00:11:48 +08:00
|
|
|
'python2.7', 'python3.1', 'pypy-c', 'jython'):
|
|
|
|
metafunc.addcall(id=name, param=name)
|
2009-12-31 00:08:45 +08:00
|
|
|
|
2010-07-27 03:15:15 +08:00
|
|
|
# XXX copied from execnet's conftest.py - needs to be merged
|
2009-12-31 00:08:45 +08:00
|
|
|
winpymap = {
|
|
|
|
'python2.7': r'C:\Python27\python.exe',
|
|
|
|
'python2.6': r'C:\Python26\python.exe',
|
|
|
|
'python2.5': r'C:\Python25\python.exe',
|
|
|
|
'python2.4': r'C:\Python24\python.exe',
|
|
|
|
'python3.1': r'C:\Python31\python.exe',
|
|
|
|
}
|
|
|
|
|
|
|
|
def getexecutable(name, cache={}):
|
|
|
|
try:
|
|
|
|
return cache[name]
|
|
|
|
except KeyError:
|
|
|
|
executable = py.path.local.sysfind(name)
|
|
|
|
if executable:
|
|
|
|
if name == "jython":
|
|
|
|
import subprocess
|
2010-07-27 03:15:15 +08:00
|
|
|
popen = subprocess.Popen([str(executable), "--version"],
|
2009-12-31 00:08:45 +08:00
|
|
|
universal_newlines=True, stderr=subprocess.PIPE)
|
|
|
|
out, err = popen.communicate()
|
|
|
|
if not err or "2.5" not in err:
|
|
|
|
executable = None
|
|
|
|
cache[name] = executable
|
|
|
|
return executable
|
|
|
|
|
|
|
|
def pytest_funcarg__anypython(request):
|
|
|
|
name = request.param
|
|
|
|
executable = getexecutable(name)
|
|
|
|
if executable is None:
|
|
|
|
if sys.platform == "win32":
|
|
|
|
executable = winpymap.get(name, None)
|
|
|
|
if executable:
|
|
|
|
executable = py.path.local(executable)
|
|
|
|
if executable.check():
|
|
|
|
return executable
|
|
|
|
py.test.skip("no %s found" % (name,))
|
|
|
|
return executable
|