[py-dev] py.test bug: large stack trace produced with full source dump on import failure

holger krekel holger at merlinux.de
Thu Jul 3 12:02:08 CEST 2008


Hi Baptiste,

On Fri, Jun 27, 2008 at 10:45 +0200, Baptiste Lepilleur wrote:
> I have run into an issue with py.test which make it pretty much unsable with 
> the following scenario:
> - a test module import another module
> - the import fails due to an exception thrown by the other module
> 
> This scenario raise two bugs (hopefully this is the scenario to reproduce 
> this bug):
> - Py.test produces a stack trace with a full source dump of the imported 
> module source
> - Information about the exception that caused the failure is missing.
> 
> The source does not end line 2269, so my guess is that py.test dump the 
> source until the source line where the exception was raised.

exactly. 

> I believe py.test should truncate the source to show only the relevant part, 
> that is ignore the 2000 lines until the global variable declaration 
> SCHEMA_SCHEMA in this case.

Hum, in other cases it might be interesting to see the context, though. 
E.g. if you have a couple of global statements where the
failing one depends on values produced by earlier ones. 

I am not sure what the exact rule should be for such contexts 
but your example showcases that we should try to improve,
indeed.  

thanks & best, 

holger

> To illustrate the issue, I've put excerpt from both the standard python 
> stacktrace and the py.test failure below:
> 
> *** Standard python traces:
> **********************
> ---
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] 
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import test_sbuildformat
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File 
> "E:\prg\vc\Lib\jsoncpp.roadmap\trunk\jsoncpp\sbuilder\src\sbuilder\testing\test_sbuildformat.py", 
> line 4, in <module>
>     import sbuilder.sbuildfileformat as sbuildfileformat
>   File 
> "E:\prg\vc\Lib\jsoncpp.roadmap\trunk\jsoncpp\sbuilder\src\sbuilder\sbuildfileformat.py", 
> line 2507, in <module>
>     SCHEMA_SCHEMA = getSchemaSchema()
>   File 
> "E:\prg\vc\Lib\jsoncpp.roadmap\trunk\jsoncpp\sbuilder\src\sbuilder\sbuildfileformat.py", 
> line 2269, in getSchemaSchema
>     error_log.makeErrorReport( tokenizer.getNormalizedInput(), 13 )
> sbuilder.sbuildfileformat.SchemaTypeParameterError
> >>>
> ---
> 
> **** Py.test traces (abrievated, full source dump is 120KO)
> **********************************************
> ============================= test process starts 
> =============================
> executable:   c:\Python25\python.exe  (2.5.2-final-0)
> using py lib: c:\Python25\lib\site-packages\py <rev unknown>
> 
> test_sbuilder.py[1] .
> test_sbuildformat.py - FAILED TO LOAD MODULE
> 
> _______________________________________________________________________________
> ________________________________ entrypoint: 
> _________________________________
> 
>     from __future__ import generators
>     import types
>     import re
> >   import sbuilder.sbuildfileformat as sbuildfileformat
> 
> [E:\prg\vc\Lib\jsoncpp.roadmap\trunk\jsoncpp\sbuilder\src\sbuilder\testing\test_sbuildformat.py:4]
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
> 
>     import types
>     import sets
>     import weakref
> 
> [....] 120KO later:
> 
> >   SCHEMA_SCHEMA = getSchemaSchema()
> 
> [E:\prg\vc\Lib\jsoncpp.roadmap\trunk\jsoncpp\sbuilder\src\sbuilder\sbuildfileformat.py:2507]
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
> 
>     def getSchemaSchema():
>         """Returns a document representing a schema of a schema.
>         This can be used to validate a schema.
>         Exceptions:
>         - DocumentParsingError if failed to parse the schema text document
>           (should never occurs, it is a bug introduced when updating the 
> schema).
>         -
>         """
>         error_log = ErrorLog( synchronous_display = False )
>         error_memo = error_log.errorMemo()
>         tokenizer = Tokenizer( getSchemaTextDocument(), 'schema.schema', 
> error_log )
>         parser = Parser( tokenizer, error_log )
>         schema_value = parser.parse()
>         if schema_value is None:
>             raise DocumentParsingError, \
>                   error_log.makeErrorReport( tokenizer.getNormalizedInput(), 
> 13 )
> 
>         try:
>             schema_schema = SchemaBuilder(error_log).getSchema( 
> schema_value )
>             if schema_schema and not schema_schema.check( error_log ):
>                 schema_schema = None
>         except SchemaTypeParameterError, error:
>             error.log( error_log )
>             schema_schema = None
>         if schema_schema is None or error_log.hasNewErrorsSinceMemo( 
> error_memo ):
>             raise SchemaTypeParameterError, \
> E                 error_log.makeErrorReport( tokenizer.getNormalizedInput(), 
> 13 )
> >                 SchemaTypeParameterError
> 
> [E:\prg\vc\Lib\jsoncpp.roadmap\trunk\jsoncpp\sbuilder\src\sbuilder\sbuildfileformat.py:2269]
> _______________________________________________________________________________
> ============= tests finished: 1 passed, 1 failed in 0.09 seconds 
> ==============
> 
> Regards,
> Baptiste.
> 
> _______________________________________________
> py-dev mailing list
> py-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
> 

-- 
Holger Krekel - freelance manager and programmer 
pylib py.test/greenlets/svn APIs: http://pylib.org 
PyPy  Python/Compiler tool chain: http://codespeak.net/pypy 
merlinux collaborative contracting: http://merlinux.eu 



More information about the Pytest-dev mailing list