From d4fe273b2fbda2592bd1238791e782c50c4fa1c2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 6 Nov 2011 15:40:17 +0000 Subject: [PATCH] fix FD leakage during pytest's own test run and add "--lsof" option to tox default test runs. the leakage came down to a problematic bit of the stdlib logging module: it takes ownerships of stdout/stderr making it hard for pytest to implement clean capturing. The current work around is to add some extra code in the setup machinery of pytest's own tests which actually closes sub-FDs. --- CHANGELOG | 1 + _pytest/__init__.py | 2 +- _pytest/pytester.py | 9 +++++++++ setup.py | 2 +- testing/conftest.py | 2 +- tox.ini | 2 +- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 955d8f914..06140d513 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Changes between 2.1.3 and [next version] ---------------------------------------- +- fix pytest's own test suite to not leak FDs - fix issue83: link to generated funcarg list - fix issue74: pyarg module names are now checked against imp.find_module false positives diff --git a/_pytest/__init__.py b/_pytest/__init__.py index adeaf25bf..b8d360007 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.1.3' +__version__ = '2.1.4.dev1' diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 3edfc6dd5..9966bb7f9 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -402,6 +402,15 @@ class TmpTestdir: config.pluginmanager.do_configure(config) self.request.addfinalizer(lambda: config.pluginmanager.do_unconfigure(config)) + # XXX we need to additionally reset FDs to prevent pen FDs + # during our test suite. see also capture.py's unconfigure XXX + # comment about logging + def finalize_capman(): + capman = config.pluginmanager.getplugin('capturemanager') + while capman._method2capture: + name, cap = capman._method2capture.popitem() + cap.reset() + self.request.addfinalizer(finalize_capman) return config def getitem(self, source, funcname="test_func"): diff --git a/setup.py b/setup.py index 1919362ef..e2eaad50b 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.1.3', + version='2.1.4.dev1', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/conftest.py b/testing/conftest.py index 2e460585c..6d20b9a4d 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -35,7 +35,7 @@ def pytest_unconfigure(config, __multicall__): __multicall__.execute() out2 = py.process.cmdexec("lsof -p %d" % pid) len2 = getopenfiles(out2) - assert len2 < config._numfiles + 7, out2 + assert len2 < config._numfiles + 15, out2 def pytest_runtest_setup(item): diff --git a/tox.ini b/tox.ini index 6605d35bd..7f96af2bf 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ indexserver= [testenv] changedir=testing -commands= py.test -rfsxX --junitxml={envlogdir}/junit-{envname}.xml [] +commands= py.test --lsof -rfsxX --junitxml={envlogdir}/junit-{envname}.xml [] deps= :pypi:pexpect :pypi:nose