Feature #620

Stack trace from Python unit tests

Added by Deil Christoph over 11 years ago. Updated over 10 years ago.

Status:NewStart date:12/05/2012
Priority:NormalDue date:
Assigned To:-% Done:

0%

Category:-
Target version:-
Duration:

Description

It should be possible to get the Python stack trace for gammalib Python unit tests.

This has been dicussed in issue #616.

Ideally there would be a “debug mode” where the developer gets the traceback on the console and can also add print statements to the code that will show up un the console.
But also for unit tests running on Jenkins it is important to have the stack trace, otherwise it will be impossible to tell for developers why a given test failed on some machine / environment they might not have access to after their commit.

I’m sure it is possible to make this work with the current gammalib unit test framework, but for the record, my suggestion would be to use the Python standard library unit test instead and not spend time reproducing this functionality (e.g. more assert statements, test discovery i.e. not having to list tests explicitly, useful verbosity levels, decorators for slow tests, ...). Another advantage is that every Python developer knows it, whereas at the moment I and any other developer has to learn the gammalib unit test framework.


Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen over 11 years ago

Just a note: don’t use print in Python code, as the command is obsolete in Python 3! We want to keep GammaLib compatible with Python3 ...

#2 Updated by Deil Christoph over 11 years ago

Jürgen Knödlseder wrote:

Just a note: don’t use print in Python code, as the command is obsolete in Python 3! We want to keep GammaLib compatible with Python3 ...

If you use print('hi') instead of print 'hi' it will work with any Python 2 and Python 3:
http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

I don’t see a reason to use the more cumbersome import sys; sys.stdout.write() all the time.

#3 Updated by Deil Christoph over 11 years ago

Concretely, the assert I wanted for the coords_check was assertLess(first, second, msg=None):
http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertLessEqual

So if there is some architecture where the test fails I would get the values of first and second in the log and I’d more quickly have an idea what is going on.

#4 Updated by Knödlseder Jürgen over 11 years ago

Christoph Deil wrote:

Jürgen Knödlseder wrote:

Just a note: don’t use print in Python code, as the command is obsolete in Python 3! We want to keep GammaLib compatible with Python3 ...

If you use print('hi') instead of print 'hi' it will work with any Python 2 and Python 3:
http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

I don’t see a reason to use the more cumbersome import sys; sys.stdout.write() all the time.

Does print('hi') work for all Python 2 versions? If this is the case, I have no problem with using simply print('hi'). We should add a note about this in the coding standard document.

#5 Updated by Knödlseder Jürgen over 11 years ago

Christoph Deil wrote:

Concretely, the assert I wanted for the coords_check was assertLess(first, second, msg=None):
http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertLessEqual

So if there is some architecture where the test fails I would get the values of first and second in the log and I’d more quickly have an idea what is going on.

We can add this feature, just create an issue.

#6 Updated by Knödlseder Jürgen over 11 years ago

  • Target version set to 00-08-00

#8 Updated by Knödlseder Jürgen over 10 years ago

  • Target version deleted (00-08-00)

Also available in: Atom PDF