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

Discussion in 'Python' started by Margie Roginski, Aug 19, 2010.

  1. 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
    Margie Roginski, Aug 19, 2010
    #1
    1. Advertising

  2. Margie Roginski

    Peter Otten Guest

    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
    Peter Otten, Aug 19, 2010
    #2
    1. Advertising

  3. On Aug 19, 12:41 am, Peter Otten <> wrote:
    > 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
    >
    > 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
    Margie Roginski, Aug 19, 2010
    #3
  4. On Aug 18, 9:20 pm, Margie Roginski <> wrote:
    > 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
    Jean-Paul Calderone, Aug 25, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Cavell

    How to get 64-bit intermediate results

    Richard Cavell, Apr 6, 2005, in forum: C++
    Replies:
    4
    Views:
    452
    msalters
    Apr 7, 2005
  2. =?iso-8859-1?B?QW5kcuk=?=

    How to avoid using files to store intermediate results

    =?iso-8859-1?B?QW5kcuk=?=, Apr 26, 2006, in forum: Python
    Replies:
    1
    Views:
    281
    Peter Otten
    Apr 26, 2006
  3. Richard Cavell

    Getting intermediate results in 64 bits

    Richard Cavell, Apr 6, 2005, in forum: C Programming
    Replies:
    14
    Views:
    527
    =?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=
    Apr 7, 2005
  4. Replies:
    4
    Views:
    344
    Eric Sosman
    Aug 2, 2006
  5. Paul  Moore
    Replies:
    1
    Views:
    383
    Paul Moore
    Oct 14, 2008
Loading...

Share This Page