This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: setUpClass exception causes explosion with "-b"
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: brandon-rhodes, ezio.melotti, michael.foord, python-dev
Priority: normal Keywords:

Created on 2011-01-22 04:13 by brandon-rhodes, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_example.py brandon-rhodes, 2011-01-22 04:13 Sample test with exception in setUpClass
Messages (5)
msg126816 - (view) Author: Brandon Rhodes (brandon-rhodes) * Date: 2011-01-22 04:13
Normally, unittest cleanly reports an exception in a setUpClass method. But if I place the attached test in a directory by itself and then run "python -m unittest discover -b" from inside of the same directory, then instead of being shown the setUpClass exception I am instead shown a long traceback because unittest seems to think that it has put a stringIO in place of sys.stdout but a file is there instead.
msg131217 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2011-03-17 04:38
Thanks for finding this Brandon. The same problem probably exists for setupmodule and the teardown variants too.

The issue is that the sys.stdout manipulation is done by result.startTest but setUpClass and setUpModule are executed by the suite outside the normal startTest / stopTest cycle. 

I think the answer is to have the stdout manipulation done in separate result methods (called by stopTest / startTest) that can also be called by the suite around the setup / teardown of class and module.
msg131267 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-17 16:48
New changeset d6abdd78d2af by Michael Foord in branch '2.7':
Issue #10979. unittest stdout buffering now works for class and module fixtures.
http://hg.python.org/cpython/rev/d6abdd78d2af
msg131271 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-17 17:43
New changeset 0f7036ea0930 by Michael Foord in branch '3.2':
Issue #10979. unittest stdout buffering now works with class and module setup and teardown.
http://hg.python.org/cpython/rev/0f7036ea0930
msg131274 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-17 17:57
New changeset 9c09ba72136e by Michael Foord in branch 'default':
Closes issue 10979. unittest buffering now works with class and module setup and teardown
http://hg.python.org/cpython/rev/9c09ba72136e
History
Date User Action Args
2022-04-11 14:57:11adminsetgithub: 55188
2011-03-17 17:57:34python-devsetstatus: open -> closed
nosy: ezio.melotti, michael.foord, brandon-rhodes, python-dev
messages: + msg131274

resolution: fixed
stage: resolved
2011-03-17 17:43:26python-devsetnosy: ezio.melotti, michael.foord, brandon-rhodes, python-dev
messages: + msg131271
2011-03-17 16:48:04python-devsetnosy: + python-dev
messages: + msg131267
2011-03-17 04:38:04michael.foordsetnosy: ezio.melotti, michael.foord, brandon-rhodes
messages: + msg131217
2011-03-17 00:46:21michael.foordsetnosy: ezio.melotti, michael.foord, brandon-rhodes
versions: + Python 3.2, Python 3.3
2011-02-02 18:00:40ezio.melottisetnosy: + ezio.melotti
2011-01-24 00:07:41michael.foordsetassignee: michael.foord
nosy: michael.foord, brandon-rhodes
2011-01-22 04:55:35r.david.murraysetnosy: + michael.foord
type: crash -> behavior
2011-01-22 04:13:29brandon-rhodescreate