Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ignored test cases in unittest

Reply
Thread Tools

ignored test cases in unittest

 
 
Terry
Guest
Posts: n/a
 
      08-16-2009
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
 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      08-16-2009
In article
<(E-Mail Removed)>,
Terry <(E-Mail Removed)> 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".
 
Reply With Quote
 
 
 
 
Terry
Guest
Posts: n/a
 
      08-16-2009
On Aug 16, 5:25*pm, Duncan Booth <(E-Mail Removed)> wrote:
> Ben Finney <(E-Mail Removed)> wrote:
> > Terry <(E-Mail Removed)> 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



 
Reply With Quote
 
David House
Guest
Posts: n/a
 
      08-17-2009
2009/8/16 Terry <(E-Mail Removed)>:
> Thanks for the solutions. I think the decorator idea is what I'm look
> for


Note that the unittest module now supports the `skip' and
`expectedFailure' decorators, which seem to describe some of the
solutions here.

See http://docs.python.org/3.1/library/u...ected-failures

--
-David
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unit test cases for Object intraction using mox/unittest jitendra gupta Python 0 03-08-2013 12:36 PM
Unittest - adding a doctest suite to unittest.main Paul Moore Python 1 10-14-2008 03:32 PM
Failing unittest Test cases Scott David Daniels Python 18 01-13-2006 12:32 AM
Putting unit test cases in the code - RDoc & UnitTest listrecv@gmail.com Ruby 9 11-15-2005 07:08 AM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments