ignored test cases in unittest

Discussion in 'Python' started by Terry, Aug 16, 2009.

  1. Terry

    Terry Guest

    Hi,

    I have some 100s unittest cases with my python program. And sometimes,
    I did quick-and-dirty work by ignoring some test cases by adding an
    'x' (or something else) to the beginning of the case name.
    As time pass by, it's very hard for me to find which test cases are
    ignored.

    It seemed the to me that python unittest module does not support the
    counting of ignored test cases directly. Is there any ready solution
    for this?

    br, Terry
     
    Terry, Aug 16, 2009
    #1
    1. Advertising

  2. Terry

    Roy Smith Guest

    In article
    <>,
    Terry <> wrote:

    > Hi,
    >
    > I have some 100s unittest cases with my python program. And sometimes,
    > I did quick-and-dirty work by ignoring some test cases by adding an
    > 'x' (or something else) to the beginning of the case name.
    > As time pass by, it's very hard for me to find which test cases are
    > ignored.


    If you are consistent in how you do this (i.e. always add an "x" to the
    beginning of the name), it should be trivial to find them all. I'm sure I
    could whip up some introspection based method, but it's easier and faster
    to just do "grep 'def.*xtest' *.py".
     
    Roy Smith, Aug 16, 2009
    #2
    1. Advertising

  3. Terry

    Terry Guest

    On Aug 16, 5:25 pm, Duncan Booth <> wrote:
    > Ben Finney <> wrote:
    > > Terry <> writes:

    >
    > >> It seemed the to me that python unittest module does not support the
    > >> counting of ignored test cases directly. Is there any ready solution
    > >> for this?

    >
    > > One solution I've seen involves:

    >
    > > * a custom exception class, ‘TestSkipped’

    >
    > > * raising that exception at the top of test cases you want to
    > >   temporarily skip

    >
    > > * a custom ‘TestResult’ class that knows about a “skipped” result

    >
    > > * a custom reporter class that knows how you want to report that result

    >
    > I'd add to that a decorator so you can quickly mark a test case as ignored
    > without editing the test itself. Also you could include a reason why it is
    > ignored:
    >
    >  @ignore("This test takes too long to run")
    >  def test_foo(self):
    >     ...
    >
    > That also means you can redefine the decorator easily if you want to try
    > running all the ignored tests.
    >
    > Another decorator useful here is one that asserts that the test will fail..
    > If the test passes then maybe someone fixed whatever was making it fail and
    > if so you want to consider re-enabling it.
    >
    >  @fails("Needs the frobnozz module to be updated")
    >  def test_whotsit(self):
    >     ...


    Thanks for the solutions. I think the decorator idea is what I'm look
    for:)
     
    Terry, Aug 16, 2009
    #3
  4. Terry

    David House Guest

    David House, Aug 17, 2009
    #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. Scott David Daniels

    Failing unittest Test cases

    Scott David Daniels, Jan 9, 2006, in forum: Python
    Replies:
    18
    Views:
    524
    Scott David Daniels
    Jan 13, 2006
  2. Replies:
    9
    Views:
    137
    Eric Hodel
    Nov 15, 2005
  3. Terry Reedy

    Re: unittest - sort cases to be run

    Terry Reedy, Aug 21, 2012, in forum: Python
    Replies:
    2
    Views:
    183
    goon12
    Aug 21, 2012
  4. Peter Otten

    Re: unittest - sort cases to be run

    Peter Otten, Aug 21, 2012, in forum: Python
    Replies:
    0
    Views:
    161
    Peter Otten
    Aug 21, 2012
  5. jitendra gupta
    Replies:
    0
    Views:
    105
    jitendra gupta
    Mar 8, 2013
Loading...

Share This Page