How to see intermediate fail results from unittest as tests are running?

M

Margie Roginski

Hi,

I am using unittest in a fairly basic way, where I have a single file
that simply defines a class that inherits from unittest.TestCase and
then within that class I have a bunch of methods that start with
"test". Within that file, at the bottom I have:

if __name__ == "__main__":
unittest.main()

This works fine and it runs all of the testxx() methods in my file.
As it runs it prints if the tests passed or failed, but if they fail,
it does not print the details of the assert that made them fail. It
collects this info up and prints it all at the end.

Ok - my question: Is there any way to get unittest to print the
details of the assert that made a test fail, as the tests are
running? IE, after a test fails, I would like to see why, rather than
waiting until all the tests are done.

I've searched the doc and even looked at the code, and it seems the
answer is no, but I'm just wondering if I'm missing something.

Thanks!

Margie
 
P

Peter Otten

Margie said:
I am using unittest in a fairly basic way, where I have a single file
that simply defines a class that inherits from unittest.TestCase and
then within that class I have a bunch of methods that start with
"test". Within that file, at the bottom I have:

if __name__ == "__main__":
unittest.main()

This works fine and it runs all of the testxx() methods in my file.
As it runs it prints if the tests passed or failed, but if they fail,
it does not print the details of the assert that made them fail. It
collects this info up and prints it all at the end.

Ok - my question: Is there any way to get unittest to print the
details of the assert that made a test fail, as the tests are
running? IE, after a test fails, I would like to see why, rather than
waiting until all the tests are done.

Not exactly what you're asking for, but 2.7 has grown a --failfast option
that tells unittest to stop on the first failure. For older Python versions
you can use nose

nosetests -x myscript.py

at http://somethingaboutorange.com/mrl/projects/nose/0.11.2/
or the unittest backport at http://pypi.python.org/pypi/unittest2

Peter
 
M

Margie Roginski

Not exactly what you're asking for, but 2.7 has grown a --failfast option
that tells unittest to stop on the first failure. For older Python versions
you can use nose

nosetests -x myscript.py

athttp://somethingaboutorange.com/mrl/projects/nose/0.11.2/
or the unittest backport athttp://pypi.python.org/pypi/unittest2

Peter

Thanks for the pointers, I will give those a try.

Margie
 
J

Jean-Paul Calderone

Hi,

I am using unittest in a fairly basic way, where I have a single file
that simply defines a class that inherits from unittest.TestCase and
then within that class I have a bunch of methods that start with
"test".  Within that file, at the bottom I have:

if __name__ == "__main__":
    unittest.main()

This works fine and it runs all of the testxx() methods in my file.
As it runs it prints if the tests passed or failed, but if they fail,
it does not print the details of the assert that made them fail.  It
collects this info up and prints it all at the end.

Ok - my question: Is there any way to get unittest to print the
details of the assert that made a test fail, as the tests are
running?  IE, after a test fails, I would like to see why, rather than
waiting until all the tests are done.

I've searched the doc and even looked at the code, and it seems the
answer is no, but I'm just wondering if I'm missing something.

Thanks!

Margie

trial (Twisted's test runner) has a `--rterrors` option which causes
it to display errors as soon as they happen.

Jean-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top