add --lsof self-testing option
--HG-- branch : trunk
This commit is contained in:
+32
-2
@@ -7,9 +7,39 @@ collect_ignore = ['../build', '../doc/_build']
|
||||
rsyncdirs = ['conftest.py', '../pytest', '../doc', '.']
|
||||
|
||||
import os, py
|
||||
pid = os.getpid()
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.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 = getopenfiles(out)
|
||||
|
||||
#def pytest_report_header():
|
||||
# return "pid: %s" % os.getpid()
|
||||
|
||||
def getopenfiles(out):
|
||||
def isopen(line):
|
||||
return ("REG" in line or "CHR" in line) and (
|
||||
"deleted" not in line and 'mem' not in line)
|
||||
return len([x for x in out.split("\n") if isopen(x)])
|
||||
|
||||
def pytest_unconfigure(config, __multicall__):
|
||||
if not hasattr(config, '_numfiles'):
|
||||
return
|
||||
__multicall__.execute()
|
||||
out2 = py.process.cmdexec("lsof -p %d" % pid)
|
||||
len2 = getopenfiles(out2)
|
||||
assert len2 < config._numfiles + 7, out2
|
||||
|
||||
def pytest_report_header():
|
||||
return "pid: %s" % os.getpid()
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
multi = getattr(metafunc.function, 'multi', None)
|
||||
|
||||
Reference in New Issue
Block a user