Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out the file name and line number of the test in python nose?

When you are running tests in nose, I would like to display the filename and line number of the test itself, especially when it fails, on the command line so I can jump to the line in emacs. I have inserted some code into case.py to print out the name, I see that I could make a plugin that handles the prepareTestCase, but my question is is there a plugin that would do that?

here is my code : nose/case.py:

import inspect

...

def runTest(self, result):

 ...

 if not isinstance(test,Failure):
    print("  File \"%s\", line %s\n" % (
        inspect.getsourcefile(test.test),
        inspect.getsourcelines(test.test)[1]))
like image 347
user2646177 Avatar asked Sep 27 '13 15:09

user2646177


1 Answers

You can get the filename of the test and test name just by running nosetest with -v option. In addition, tests that fail will dump a full stack trace on error (which has line numbers). You can also use --pdb and --pdb-failure options to get into pdb debugger immediately after error or test failure.

Nose-progressive plugin has many bells and whistles in terms of formatting the output of the tests, including changing the template to satisfy any editor. Also, check out this nosemacs - emacs extension to provide easy nosetest integration. And if you just want line numbers, nose-machineout is your friend.

like image 127
Oleksiy Avatar answered Sep 30 '22 19:09

Oleksiy