From e45a33f0299cd300e68abb47dd9f9de5e86648a4 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 1 Apr 2014 14:13:11 -0700 Subject: [PATCH] testing/conftest.py: Reintialize config._openfiles for each test And no longer need getopenfiles or config._numfiles --HG-- branch : refactor_LsofFdLeakChecker --- testing/conftest.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/testing/conftest.py b/testing/conftest.py index c2d49a23c..ebd5b1b6f 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -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