[Python-ideas] @unittest.skip_others decorator

Jerry Seutter jseutter at gmail.com
Mon Aug 16 23:01:39 CEST 2010


Hi, you may be interested in this.  It's part of the unittest module that
ships with Python:

=======================
./python.exe -m unittest test.test_call.CFunctionCalls.test_varargs0
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
=======================

An added bonus is that this works across many Python projects.

Hope this helps,

Jerry Seutter


On Mon, Aug 16, 2010 at 2:37 PM, Giampaolo Rodolà <g.rodola at gmail.com>wrote:

> 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/
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100816/99ee1647/attachment.html>


More information about the Python-ideas mailing list