Error in atexit._run_exitfuncs

Issue #133 new
Anonymous created an issue

Trying to use py.test version 2.0.0.dev18 I get tracebacks with atexit and logging.

I am unable to provide test examples since this is only failing on a very specific part of our application and can't get a way of reproducing it manually (outside of our app).

If I go back to py.test version 1.3.4 the error goes away.

This traceback happens even if the test passes but only with 2.0.0.dev18

Traceback: {{{

modeltests/test_account.py:632: TestAccount.test_total_users PASSED

======================================= 22 tests deselected by 'users' ======================================== =================================== 1 passed, 22 deselected in 2.78 seconds =================================== Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, kargs) File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py", line 1472, in shutdown h.flush() File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/__init__.py", line 740, in flush self.stream.flush() ValueError: I/O operation on closed file Error in sys.exitfunc: Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, kargs) File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/init.py", line 1472, in shutdown h.flush() File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/logging/init.py", line 740, in flush self.stream.flush() ValueError: I/O operation on closed file }}}

Comments (6)

  1. Alfredo Deza
    • marked as bug
    • removed version

    Bah, it seems I wasn't logged in when I created the ticket... hope this comment allows tracking it via email.

    Also, there seems no way of selecting "2.0.0" as the version affected by this problem.

  2. Alfredo Deza

    I apologize for not replying earlier... it seems I never got the email alerting me of a response :(

    I will try that plus migrate our whole testing environment to py.test 2.0 ASAP. I will keep reporting issues (if any) and will close this if I can't get the issue to replicate.

    Thanks for your attention to this!

  3. eduardo schettino

    I am getting this error on py.test 2.0

    I've done some investigation... The stream that is already closed when the logging tries to flush is py._io.capture.EncodedFile

    Here is stack trace for the moment the stream is closed:

    > /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/py/_io/capture.py(145)__getattr__()
    -> return getattr(self._stream, name)
    (Pdb) w
      /home/eduardo/work/mininiss/py25/bin/py.test(8)<module>()
    -> load_entry_point('pytest==2.0.0', 'console_scripts', 'py.test')()
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(452)main()
    -> exitstatus = hook.pytest_cmdline_main(config=config)
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(406)__call__()
    -> return self._docall(methods, kwargs)
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(417)_docall()
    -> res = mc.execute()
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(338)execute()
    -> res = method(**kwargs)
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/session.py(82)pytest_cmdline_main()
    -> config.pluginmanager.do_unconfigure(config)
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(259)do_unconfigure()
    -> config.hook.pytest_unconfigure(config=config)
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(406)__call__()
    -> return self._docall(methods, kwargs)
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(417)_docall()
    -> res = mc.execute()
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/core.py(338)execute()
    -> res = method(**kwargs)
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/_pytest/capture.py(29)pytest_unconfigure()
    -> cap.reset()
      /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/py/_io/capture.py(175)reset()
    -> errfile.close()
    > /home/eduardo/work/mininiss/py25/lib/python2.5/site-packages/py/_io/capture.py(145)__getattr__()
    -> return getattr(self._stream, name)
    
    

    I am not sure how logging ended up having this as a stream because self._stream is not stderr...

    Please let me know if you need any other info. I will try to investigate it more later.

  4. eduardo schettino

    It is trivial to reproduce the error with anything that uses logging

    import logging
    def test_133():
        logging.error('x')
    

    I guess I understand the problem now. any application that tries to close stdout/stderr will show this behavior. Why is it required to pytest to close these?

  5. Log in to comment