[py-dev] py.test munging strings in asserts?

Jan Balster jan at balster.info
Fri Apr 21 12:16:08 CEST 2006


Hi Timothy!

The output is truncated to 240 characters, which is exactly the length of your
strings in the output. The dots are only indicators, that the output was truncated.
See py/test/terminal/terminal.py:439 and py/code/save_repr.py for explanations.
As stated in the comments, we probably need a command line switch to toggle the
behavior.

The test of equality is not affected by the truncation of the output! If you
write the text to stdout or a file, you will see it in it's whole glory.

example:

def test_output():
    long_string = '/' * 238 # 238 + two "'" for the string representation == 240
    longer_string = 'start' + long_string + 'end' # will be truncated

    print longer_string

    assert long_string == longer_string

If you have any further questions, don't hesitate to ask!

Cheers,
  Jan


> I'm writing a test to test some HTML output and the test fails for
> several reasons, all of which I understand but one.
> 
> Here's the output (I've surrounded the problem area with *** to make
> it a little more visible.
> 
> ========================================================
>    def test_error_summary():
>        text = '''<html>
>    <head>
>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>    <title>PyTestMate</title>
> 
>    <style type="text/css">
>    .error {color : #FF0000}
>    </style>
> 
>    </head>
>    <body>
>    <p>Error in <a
> href="txmt://open/?url=file:///Users/tjg/code/textmate/test_pytestmate.py&line=17">/Users/tjg/code/textmate/test_pytestmate.py</a>
> at line 17</p>
>    <pre>
>    [/Users/tjg/code/textmate/test_pytestmate.py:17]
>    </pre>
>    </body>
>    </html>'''
> 
>        assert pytestmate.create_output(
>            ['[/Users/tjg/code/textmate/test_pytestmate.py:17]']
> E           ) == text
>>       assert '<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n<title>PyTestMate</title>\n\n***<...mate/test_pytestmate.py***</a> at line 17<br/><pre>[/Users/tjg/code/textmate/test_pytestmate.py:17]</pre></body>\n</html>' == '<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n<title>PyTestMate</title>\n\n***<...st_pytestmate.py***</a> at line 17</p>\n<pre>\n[/Users/tjg/code/textmate/test_pytestmate.py:17]\n</pre>\n</body>\n</html>'
>         +  where '<html>\n<head>\n<meta http-equiv="Content-Type"
> content="text/html; charset=utf-8"
> />\n<title>PyTestMate</title>\n\n<...mate/test_pytestmate.py</a> at
> line 17<br/><pre>[/Users/tjg/code/textmate/test_pytestmate.py:17]</pre></body>\n</html>'
> = <function create_output at
> 0x42e870>(['[/Users/tjg/code/textmate/test_pytestmate.py:17]'])
>         +    where <function create_output at 0x42e870> =
> pytestmate.create_output
> 
> [/Users/tjg/code/textmate/test_pytestmate.py:55]
> ===============================================
> 
> granted the left side of that equality could be messed up due to
> create_output() NOT doing the right thing. But the right side is
> simply the contents of the variable "text" so WHY is the first part of
> the path being substituted with "..."?
> 
> Any insight greatly appreciated.
> 
> 
> --
> Stand Fast,
>     tjg.
> _______________________________________________
> py-dev mailing list
> py-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
> 



More information about the Pytest-dev mailing list