diff --git a/pytest/__init__.py b/pytest/__init__.py index 280549c0e..afc40b3f1 100644 --- a/pytest/__init__.py +++ b/pytest/__init__.py @@ -5,7 +5,7 @@ see http://pytest.org for documentation and details (c) Holger Krekel and others, 2004-2010 """ -__version__ = '2.0.0.dev9' +__version__ = '2.0.0.dev10' __all__ = ['config', 'cmdline'] diff --git a/setup.py b/setup.py index c53444bcf..6c79bca6b 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.0.0.dev9', + version='2.0.0.dev10', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/conftest.py b/testing/conftest.py index ead6b5577..45c0d6eb2 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -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)