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) *  |
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) *  |
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) *  |
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) *  |
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) *  |
Date: 2021-11-29 23:59 |
Reproduced on 3.11. |
|
|
msg407366 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
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) *  |
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) *  |
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) *  |
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) *  |
Date: 2021-12-11 00:36 |
Thanks, Serhiy! ✨ 🍰 ✨ |
|
|