internal test runs: do inline_run() without io-capturing

as this nested capturing can leave open FDs which breaks
larger test runs.  also introduce an internal option "--lsof"
for checking the number of file descriptors

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-05-25 12:24:51 +02:00
parent 545aab85f2
commit 9173b60677
2 changed files with 23 additions and 1 deletions

View File

@ -7,7 +7,9 @@ collect_ignore = ['build', 'doc/_build']
rsyncdirs = ['conftest.py', 'bin', 'py', 'doc', 'testing'] rsyncdirs = ['conftest.py', 'bin', 'py', 'doc', 'testing']
import py import os, py
pid = os.getpid()
def pytest_addoption(parser): def pytest_addoption(parser):
group = parser.getgroup("pylib", "py lib testing options") group = parser.getgroup("pylib", "py lib testing options")
group.addoption('--sshhost', group.addoption('--sshhost',
@ -16,7 +18,26 @@ def pytest_addoption(parser):
group.addoption('--runslowtests', group.addoption('--runslowtests',
action="store_true", dest="runslowtests", default=False, action="store_true", dest="runslowtests", default=False,
help=("run slow tests")) help=("run slow tests"))
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])
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
def pytest_funcarg__sshhost(request): def pytest_funcarg__sshhost(request):
val = request.config.getvalue("sshhost") val = request.config.getvalue("sshhost")

View File

@ -185,6 +185,7 @@ class TmpTestdir:
return reports[0] return reports[0]
def inline_run(self, *args): def inline_run(self, *args):
args = ("-s", ) + args # otherwise FD leakage
config = self.parseconfig(*args) config = self.parseconfig(*args)
config.pluginmanager.do_configure(config) config.pluginmanager.do_configure(config)
session = config.initsession() session = config.initsession()