How to see intermediate fail results from unittest as tests are running?
Peter Otten
__peter__ at web.de
Thu Aug 19 03:41:02 EDT 2010
Margie Roginski wrote:
> 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
More information about the Python-list
mailing list