Skip to content

Commit

Permalink
avoid "IOError: Bad Filedescriptor" on pytest shutdown by not closing
Browse files Browse the repository at this point in the history
the internal dupped stdout (fix is slightly hand-wavy but work).
  • Loading branch information
hpk42 committed Oct 2, 2013
1 parent 16d9854 commit 0719602
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Changes between 2.4.1 and 2.4.2
-----------------------------------

- avoid "IOError: Bad Filedescriptor" on pytest shutdown by not closing
the internal dupped stdout (fix is slightly hand-wavy but work).

Changes between 2.4.0 and 2.4.1
-----------------------------------

Expand Down
2 changes: 1 addition & 1 deletion _pytest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#
__version__ = '2.4.1'
__version__ = '2.4.2.dev1'
2 changes: 1 addition & 1 deletion _pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def teardown():
except ValueError:
pass
early_config.pluginmanager.add_shutdown(teardown)
# make sure logging does not raise exceptions if it is imported
# make sure logging does not raise exceptions at the end
def silence_logging_at_shutdown():
if "logging" in sys.modules:
sys.modules["logging"].raiseExceptions = False
Expand Down
13 changes: 8 additions & 5 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,23 @@ def pytest_addoption(parser):

def pytest_configure(config):
config.option.verbose -= config.option.quiet

# we try hard to make printing resilient against
# later changes on FD level. (unless capturing is turned off)
stdout = py.std.sys.stdout
capture = config.option.capture != "no"
if capture and hasattr(os, 'dup') and hasattr(stdout, 'fileno'):
# later changes on FD level. (unless capturing is off/sys)
stdout = sys.stdout
if config.option.capture == "fd" and hasattr(os, "dup"):
try:
newstdout = py.io.dupfile(stdout, buffering=1,
encoding=stdout.encoding)
except ValueError:
pass
else:
config._cleanup.append(lambda: newstdout.close())
assert stdout.encoding == newstdout.encoding
stdout = newstdout
#we don't close on shutdown because this can
#cause logging to fail on a second close
#(not really clear to me how it happens exactly, though)
#config.pluginmanager.add_shutdown(fin)

reporter = TerminalReporter(config, stdout)
config.pluginmanager.register(reporter, 'terminalreporter')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def main():
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
version='2.4.1',
version='2.4.2.dev1',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
Expand Down

0 comments on commit 0719602

Please sign in to comment.