[Python-checkins] cpython (3.2): Issue #12400: runtest() truncates the StringIO stream before a new test

Terry Reedy tjreedy at udel.edu
Wed Jun 29 19:05:13 CEST 2011


On 6/29/2011 11:30 AM, victor.stinner wrote:

> summary:
>    Issue #12400: runtest() truncates the StringIO stream before a new test
>
> files:
>    Lib/test/regrtest.py |  1 +
>    1 files changed, 1 insertions(+), 0 deletions(-)
>
>
> diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
> --- a/Lib/test/regrtest.py
> +++ b/Lib/test/regrtest.py
> @@ -793,6 +793,7 @@
>               if runtest.stringio is None:
>                   runtest.stringio = io.StringIO()
>               stream = runtest.stringio
> +            stream.truncate(0)

You *MUST* seek to 0 to reset the file position, which I presume is your 
intention. 'Resize' does not mean what you probably think is does (and 
what I thought once either ;-).

"truncate(size=None)
Resize the stream to the given size in bytes (or the current position if 
size is not specified). The current stream position isn’t changed."

 >>> s=io.StringIO()
 >>> s.write('abc')
3
 >>> s.truncate(0)
0
 >>> s.tell()
3
 >>> s.write('abc')
3
 >>> s.getvalue()
'\x00\x00\x00abc'

Terry



More information about the Python-checkins mailing list