Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3796132
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:11:21+00:00 2026-05-19T13:11:21+00:00

I am using py.test to test some modules of mine that contains quite a

  • 0

I am using py.test to test some modules of mine that contains quite a bit of stdlib logging. I would of course like for the logging to log to stdout, which is captured by py.test, so that I will get all relevant logging messages if a test fails.

The problem with this is that the logging module ends up trying to log messages to the ‘stdout’-object provided by py.test after this object has been discarded by py.test. That is, I get:

Traceback (most recent call last):
  File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.6/logging/__init__.py", line 1508, in shutdown
    h.flush()
  File "/usr/lib/python2.6/logging/__init__.py", line 754, in flush
    self.stream.flush()
ValueError: I/O operation on closed file

If I turn off capturing with -s, I don’t have any problems, but of course that makes the test output unreadable with irrelevant logging.

Can anyone tell me the proper way to integrate stdlib logging with py.test?

(I tried looking at this, where it looks like it should just work without issues, so it didn’t help me much)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:11:22+00:00Added an answer on May 19, 2026 at 1:11 pm

    Logging/capturing interactions are to better work with the upcoming 2.0.1 release, which you can install already as a development snapshot by:

    pip install -i http://pypi.testrun.org pytest 
    

    You should get at least “2.0.1.dev9” when you type “py.test –version” afterwards. And the problem/error your posted should now be gone.

    A bit of background: the logging package insists on “owning” the streams it uses, and by default it grabs sys.stderr and insists to close it at process exit, registered via the atexit module. py.test substitutes sys.stdout with a temporary file in order to snapshot output (including output at file-descriptor level in order to also catch subprocess output). So py.test evolved to be very careful to always use the same temporary file as to not have logging’s atexit-code complain.

    Not that you can also install the [pytest-capturelog][1] plugin which will help some more with dealing with logging output.

    [1] http://pypi.python.org/pypi/pytest-capturelog/0.7

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some test cases, and I've got a test case that is using
I am using py.test to write some tests and in my tests I utilize
I am using WCF REST Preview 2 to test some REST services. The package
I'm trying to retrofit some tests using Test::More to legacy code and I've bumped
I am trying to test some other Python code repeatedly, using all possible combinations
I'm using Google Test Framework to set some unit tests. I have got three
I am trying to test out some Dapper stuff using LinqPad. Dapper needs a
I am using Selenium IDE Firefox plugin to create some test cases. I click
I'm trying to work out why some of my test cases (using RhinoMocks 3.6
I have some .csv files which I'm using as part of a test bench.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.