classification
Title: texttestresult should decorate the stream with _WritelnDecorator
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: elopio, michael.foord
Priority: normal Keywords: patch

Created on 2012-12-20 16:16 by elopio, last changed 2020-05-31 12:49 by serhiy.storchaka.

Files
File name Uploaded Description Edit
fix-16739-texttestresult_writeln.patch elopio, 2012-12-20 18:12 patch review
fix-16739-texttestresult_writeln-v2.patch elopio, 2013-01-03 00:35 patch that doesn't decorate a stream that doesn't need it review
Messages (4)
msg177833 - (view) Author: Leo Arias (elopio) Date: 2012-12-20 16:16
Using the unittest's texttestresult with stdout and verbosity 2 will fail because that stream doesn't have a writeln method.

  File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/usr/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python2.7/unittest/suite.py", line 108, in run
    test(result)
  File "/usr/lib/python2.7/dist-packages/unittest2/case.py", line 398, in __call__
    return self.run(*args, **kwds)
  File "/usr/lib/python2.7/dist-packages/unittest2/case.py", line 375, in run
    result.addSuccess(self)
  File "/home/elopio/canonical/ubuntuone/photos-acceptance-2/lib/testtools/testresult/real.py", line 253, in addSuccess
    return self._dispatch('addSuccess', test, details=details)
  File "/home/elopio/canonical/ubuntuone/photos-acceptance-2/lib/testtools/testresult/real.py", line 231, in _dispatch
    for result in self._results)
  File "/home/elopio/canonical/ubuntuone/photos-acceptance-2/lib/testtools/testresult/real.py", line 231, in <genexpr>
    for result in self._results)
  File "/home/elopio/canonical/ubuntuone/photos-acceptance-2/lib/testtools/testresult/real.py", line 555, in addSuccess
    return self.decorated.addSuccess(test)
  File "/usr/lib/python2.7/unittest/runner.py", line 60, in addSuccess
    self.stream.writeln("ok")
AttributeError: 'file' object has no attribute 'writeln'

It would be nice if the stream is decorated with _WritelnDecorator, as it is done on TextTestRunner.
msg177841 - (view) Author: Leo Arias (elopio) Date: 2012-12-20 18:12
A test with a fix.

I'm not sure if this is the way to go, because the stream in TextTestRunner will be decorated twice.
msg177845 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2012-12-20 18:23
TextTestResult could decorate a raw stream (and not redecorate an already decorated one).
msg178865 - (view) Author: Leo Arias (elopio) Date: 2013-01-03 00:35
What if we check if the stream has the writeln method?
History
Date User Action Args
2020-05-31 12:49:41serhiy.storchakasetversions: + Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10, - Python 2.7
2013-01-03 00:35:41elopiosetfiles: + fix-16739-texttestresult_writeln-v2.patch

messages: + msg178865
2012-12-20 18:23:07michael.foordsetassignee: michael.foord

messages: + msg177845
nosy: + michael.foord
2012-12-20 18:13:00elopiosetfiles: + fix-16739-texttestresult_writeln.patch
keywords: + patch
messages: + msg177841
2012-12-20 16:16:21elopiocreate