Issue 13236: unittest needs more flush calls (original) (raw)

Created on 2011-10-20 19:02 by petere, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testcase.py petere,2011-10-26 17:22 test case
Pull Requests
URL Status Linked Edit
PR 29864 merged serhiy.storchaka,2021-11-30 12:00
PR 29929 merged serhiy.storchaka,2021-12-05 20:54
PR 30039 merged miss-islington,2021-12-10 23:36
Messages (12)
msg146043 - (view) Author: Peter Eisentraut (petere) * Date: 2011-10-20 19:02
I'm using the TextTestRunner class in unittest/runner.py with a special file-like object passed in as stream. Doing this loses some output, because the run() method (and some lower-level methods) don't always call flush() on the stream. There is also no obvious cleanup method in the runner class that might do this, so I assume run() should do that itself. Right now, it looks like it assumes that either the stream is effectively unbuffered, like stderr, or that the end of the program might flush things, but that doesn't always apply. It looks like the best fix would be a self.stream.flush() call at the end of run(). Another flush() call at the end of printErrorList() would also help. (In the meantime, I have fixed up my special file-like class to flush its internal buffers when a newline is seen, which kind of works, but a proper cleanup of this matter would still be nice.)
msg146044 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-10-20 19:20
How can a lack of flushes lose output? Delay it maybe, but unless your file class is broken I don't see how data would be lost.
msg146051 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-10-20 21:00
Can you provide a minimal test case to reproduce the issue?
msg146446 - (view) Author: Peter Eisentraut (petere) * Date: 2011-10-26 17:22
Attached is a test file. The key here is that I'm running the unittest suite inside of a long-running server process, so there is no predictable point of exit and cleanup. Therefore, the steps I show at the end of the file should be run in an interactive interpreter. Here is what I see: >>> import unittest >>> import testcase >>> unittest.main(module=testcase) .F. ====================================================================== FAIL: test_three (testcase.test) ---------------------------------------------------------------------- Traceback (most recent call last): File "testcase.py", line 35, in test_three self.fail("intentional failure") AssertionError: intentional failure ---------------------------------------------------------------------- Ran 3 tests in 0.002s FAILED (failures=1) That's good. But: >>> import unittest >>> import testcase >>> unittest.main(module=testcase, testRunner=testcase.FunnyTestRunner, exit=False) . F . <unittest.main.TestProgram object at 0xf718fd4c> You see, the test report at the end is missing. I'm happy to consider other ways of addressing this, if anyone has an idea.
msg229420 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2014-10-15 09:09
ping about this bug, do you have the same problem with the last version of Python 3.4 and with Python 2.7.8 ?
msg229459 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-10-15 15:16
And if the issue still holds, please provide a patch adding the appropriate flush() calls.
msg407338 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-11-29 23:59
Reproduced on 3.11.
msg407366 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-11-30 12:02
I do not remember details, but I encountered this issue (maybe when run tests in subprocesses?).
msg407682 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-04 18:57
New changeset f42a06ba279c916fb67289e47f9bc60dc5dee4ee by Serhiy Storchaka in branch 'main': bpo-13236: Flush the output stream more often in unittest (GH-29864) https://github.com/python/cpython/commit/f42a06ba279c916fb67289e47f9bc60dc5dee4ee
msg408268 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-12-10 23:36
New changeset 83fa1291fd0a25216a4a9e990f423682fda67cbe by Serhiy Storchaka in branch '3.10': [3.10] bpo-13236: Flush the output stream more often in unittest (GH-29864) (GH-29929) https://github.com/python/cpython/commit/83fa1291fd0a25216a4a9e990f423682fda67cbe
msg408284 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-12-11 00:34
New changeset d55a03e02e69fb7f639998de71ed3f44c2f4f999 by Miss Islington (bot) in branch '3.9': [3.10] bpo-13236: Flush the output stream more often in unittest (GH-29929) (GH-30039) https://github.com/python/cpython/commit/d55a03e02e69fb7f639998de71ed3f44c2f4f999
msg408285 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-12-11 00:36
Thanks, Serhiy! ✨ 🍰 ✨
History
Date User Action Args
2022-04-11 14:57:22 admin set github: 57445
2021-12-11 00:36:03 lukasz.langa set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2021-12-11 00:34:50 lukasz.langa set messages: +
2021-12-10 23:36:24 miss-islington set nosy: + miss-islingtonpull_requests: + <pull%5Frequest28265>
2021-12-10 23:36:19 lukasz.langa set nosy: + lukasz.langamessages: +
2021-12-05 20:54:52 serhiy.storchaka set pull_requests: + <pull%5Frequest28153>
2021-12-04 18:57:27 serhiy.storchaka set messages: +
2021-11-30 12:02:18 serhiy.storchaka set versions: + Python 3.9, Python 3.10
2021-11-30 12:02:06 serhiy.storchaka set messages: +
2021-11-30 12:00:08 serhiy.storchaka set keywords: + patchnosy: + serhiy.storchakapull_requests: + <pull%5Frequest28091>stage: test needed -> patch review
2021-11-29 23:59:34 iritkatriel set nosy: + iritkatrielmessages: + versions: + Python 3.11, - Python 2.7, Python 3.2
2014-10-16 22:17:38 pitrou set nosy: + rbcollins
2014-10-15 15:16:53 pitrou set nosy: + pitroumessages: +
2014-10-15 09:09:46 matrixise set nosy: + matrixisemessages: +
2011-10-26 17:22:17 petere set files: + testcase.pymessages: +
2011-10-20 21:00:47 ezio.melotti set versions: - Python 3.1nosy: + ezio.melottimessages: + stage: test needed
2011-10-20 19:20:10 r.david.murray set nosy: + r.david.murraymessages: + versions: - Python 2.6
2011-10-20 19:02:03 petere create