From 605f36c905275f60ef3ecdb38b28c2470d194c92 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 9 Jul 2009 13:12:00 +0200 Subject: [PATCH] fix logging interaction issue --HG-- branch : trunk --- CHANGELOG | 3 +++ py/test/plugin/pytest_runner.py | 7 +++++++ py/test/plugin/test_pytest_runner.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 0d144a762..dccc2a7fd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 1.0.0b7 and 1.0.0b8 ===================================== +* workaround a logging module interaction ("closing already closed + files"). Thanks to Sridhar Ratnakumar for triggering. + * if plugins use "py.test.importorskip" for importing a dependency only a warning will be issued instead of exiting the testing process. diff --git a/py/test/plugin/pytest_runner.py b/py/test/plugin/pytest_runner.py index 039d45899..cfff2023f 100644 --- a/py/test/plugin/pytest_runner.py +++ b/py/test/plugin/pytest_runner.py @@ -24,6 +24,13 @@ def pytest_sessionfinish(session, exitstatus, excrepr=None): if hasattr(session.config, '_setupstate'): session.config._setupstate.teardown_all() + # prevent logging module atexit handler from choking on + # its attempt to close already closed streams + # see http://bugs.python.org/issue6333 + mod = py.std.sys.modules.get("logging", None) + if mod is not None: + mod.raiseExceptions = False + def pytest_make_collect_report(collector): call = collector.config.guardedcall( lambda: collector._memocollect() diff --git a/py/test/plugin/test_pytest_runner.py b/py/test/plugin/test_pytest_runner.py index 9286cad57..e0e7c2348 100644 --- a/py/test/plugin/test_pytest_runner.py +++ b/py/test/plugin/test_pytest_runner.py @@ -286,3 +286,17 @@ def test_functional_boxed(testdir): "*CRASHED*", "*1 failed*" ]) + +def test_logging_interaction(testdir): + p = testdir.makepyfile(""" + def test_logging(): + import logging + import StringIO + stream = StringIO.StringIO() + logging.basicConfig(stream=stream) + stream.close() # to free memory/release resources + """) + result = testdir.runpytest(p) + assert result.stderr.str().find("atexit") == -1 + +