testing/conftest.py: Reintialize config._openfiles for each test

And no longer need getopenfiles or config._numfiles

--HG--
branch : refactor_LsofFdLeakChecker
This commit is contained in:
Marc Abramowitz 2014-04-01 14:13:11 -07:00
parent 064e79761c
commit e45a33f029
1 changed files with 3 additions and 12 deletions

View File

@ -38,7 +38,8 @@ def pytest_addoption(parser):
action="store_true", dest="lsof", default=False,
help=("run FD checks if lsof is available"))
def pytest_configure(config):
def pytest_runtest_setup(item):
config = item.config
config._basedir = py.path.local()
if config.getvalue("lsof"):
try:
@ -46,18 +47,10 @@ def pytest_configure(config):
config._openfiles = config._fd_leak_checker.get_open_files()
except py.process.cmdexec.Error:
pass
else:
config._numfiles = len(config._openfiles)
#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 and "txt" not in line)
return [x for x in out.split("\n") if isopen(x)]
def check_open_files(config):
lines2 = config._fd_leak_checker.get_open_files()
new_fds = sorted(set([t[0] for t in lines2]) - set([t[0] for t in config._openfiles]))
@ -71,13 +64,11 @@ def check_open_files(config):
error.append("*** After:")
error.extend([str(f) for f in lines2])
error.append(error[0])
# update numfile so that the overall test run continuess
config._numfiles = len(lines2)
raise AssertionError("\n".join(error))
def pytest_runtest_teardown(item, __multicall__):
item.config._basedir.chdir()
if hasattr(item.config, '_numfiles'):
if hasattr(item.config, '_openfiles'):
x = __multicall__.execute()
check_open_files(item.config)
return x