[Python-ideas] @unittest.skip_others decorator

Giampaolo Rodolà g.rodola at gmail.com
Mon Aug 16 22:37:07 CEST 2010


Hello,
when working on a test suite, no matter if writing new test cases from
scratch or modifying an existing one, the need of temporarily
excluding other tests and focus on that particular one is very common
(at least for me).
This is especially true when working on a test suite which contains a
lot of tests producing a very verbose output result or which takes a
lot to complete.

What I usually do in such cases is to scroll down until test_main()
function, manually change support.run_unittest() ilke this:

-    support.run_unittest(TestCase1, TestCase2, TestCase3, TestCase4)
+    support.run_unittest(TestCase4)

...and then comment out all the test cases in TestCase4 class except
the one I'm interested in.
This is obviously not very flexible, then I thought that maybe
unittest (or test/support module, I'm not sure) could provide a
specific decorator for temporarily running only one specific test
class(es) or method(s).
The decorator could be used in 3 ways:

== use case #1 ==

@unittest.exclude_others
class TestCase1:
     ...

All TestCase1 test cases are run, TestCase2, TestCase3 and TestCase4
classes are excluded.


== use case #2 ==

class TestCase1:

   @unittest.exclude_others
    def test_something(self):
         ....

All TestCase1.* tests are excluded except "test_something".
TestCase2, TestCase3 and TestCase4 are run.


== use case #3 ==

@unittest.exclude_others
class TestCase1:

   @unittest.exclude_others
    def test_something(self):
         ....
Only TestCase1.test_something() is run (this is the most common use case).


Thoughts?


Kindest regards,


--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/



More information about the Python-ideas mailing list