[Python-ideas] Easily reference a single unittest from cmdline

Terry Reedy tjreedy at udel.edu
Sat Dec 7 23:03:05 CET 2013


On 12/7/2013 8:03 AM, Giampaolo Rodola' wrote:
> During the development process it is very common to implement a new
> functionality, write a test for it

Or vice versa ;-)

> and then run tests.
> I don't want to run *all* tests though, but only the new one which I just wrote.

I presume for time reasons. The idlelib test modules I have written so 
far run under a second, so this is not an issue for me. For me, a test 
module would have to run several seconds, at least, to be worth 
switching to a console window instead of hitting F5.

> Currently unittest module lets you do this via cmdline with:
>
> python -m unittest test.test_module.TestClass.test_method
>
> This is not very practical though as you have to figure out the name
> of the module (easy) and the name of the test class (something which I
> *never* remember).

I mostly use ClassnameTest or FunctionnameTest.

> Proposal is to allow a wildcard notation like this:
>
> python -m unittest test.test_module.*test_method*

I think this should better be
python -m unittest "test.test_module.*.test_method"

> python -m unittest *test_method*

I think you left something out here.

> What I expect from unittest is to execute only the test methods
> matching "*test_method*".

Inspired by you second post, how about

python -m unittest test.test_module -t test_method1 test_method2 ...

which gives more flexibility. Of course, test_x will match multiple 
tests if test_x appears in multiple testcase classes. I believe there 
are other proposals for more flexibility in picking which tests to run. 
There may be a tracker issue already.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list