From 9173b60677a6eb8a7cf06e62cc417aee83d61e28 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 25 May 2010 12:24:51 +0200 Subject: [PATCH] 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 --- conftest.py | 23 ++++++++++++++++++++++- py/_plugin/pytest_pytester.py | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index e139ed799..83b986613 100644 --- a/conftest.py +++ b/conftest.py @@ -7,7 +7,9 @@ collect_ignore = ['build', 'doc/_build'] rsyncdirs = ['conftest.py', 'bin', 'py', 'doc', 'testing'] -import py +import os, py +pid = os.getpid() + def pytest_addoption(parser): group = parser.getgroup("pylib", "py lib testing options") group.addoption('--sshhost', @@ -16,7 +18,26 @@ def pytest_addoption(parser): group.addoption('--runslowtests', action="store_true", dest="runslowtests", default=False, 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): val = request.config.getvalue("sshhost") diff --git a/py/_plugin/pytest_pytester.py b/py/_plugin/pytest_pytester.py index 0fb4f24de..bb6790d75 100644 --- a/py/_plugin/pytest_pytester.py +++ b/py/_plugin/pytest_pytester.py @@ -185,6 +185,7 @@ class TmpTestdir: return reports[0] def inline_run(self, *args): + args = ("-s", ) + args # otherwise FD leakage config = self.parseconfig(*args) config.pluginmanager.do_configure(config) session = config.initsession()