Easily reference a single unittest from cmdline
During the development process it is very common to implement a new functionality, write a test for it and then run tests. I don't want to run *all* tests though, but only the new one which I just wrote. 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). Proposal is to allow a wildcard notation like this: python -m unittest test.test_module.*test_method* python -m unittest *test_method* What I expect from unittest is to execute only the test methods matching "*test_method*". This is related to an old proposal I raised 3 years ago: https://mail.python.org/pipermail/python-ideas/2010-August/007992.html After that dicussion I ended up coming up with a decorator for skipping tests: http://code.activestate.com/recipes/578234-unittestskip_others-decorator/?in... ...but I never find it really practical and I ended up abandoning it. In retrospective, I think the cmdline is the right place from where such a thing should be controlled. Thoughts? --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/
I just took a look at nosetests. It provides a similar thing and lets you use a regular expression (which indeed makes a lot more sense than using wildcards) It works like this: nosetests test/test_module -m test_name --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/ On Sat, Dec 7, 2013 at 2:03 PM, Giampaolo Rodola' <g.rodola@gmail.com> wrote:
During the development process it is very common to implement a new functionality, write a test for it and then run tests. I don't want to run *all* tests though, but only the new one which I just wrote. 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).
Proposal is to allow a wildcard notation like this:
python -m unittest test.test_module.*test_method* python -m unittest *test_method*
What I expect from unittest is to execute only the test methods matching "*test_method*".
This is related to an old proposal I raised 3 years ago: https://mail.python.org/pipermail/python-ideas/2010-August/007992.html After that dicussion I ended up coming up with a decorator for skipping tests: http://code.activestate.com/recipes/578234-unittestskip_others-decorator/?in... ...but I never find it really practical and I ended up abandoning it.
In retrospective, I think the cmdline is the right place from where such a thing should be controlled.
Thoughts?
--- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/
On Dec 07, 2013, at 02:27 PM, Giampaolo Rodola' wrote:
I just took a look at nosetests. It provides a similar thing and lets you use a regular expression (which indeed makes a lot more sense than using wildcards) It works like this:
nosetests test/test_module -m test_name
I use nose2 in several projects and have a nice little plugin that reproduces the most useful (for me) bits of zope testrunner for specifying test patterns. I can usually just do something like $ nose2 -P test_this_one_thing $ nose2 -P TestThisWholeClass $ nose2 -P test_module $ nose2 -P test_things.rst http://tinyurl.com/l2trn4a -Barry P.S. Yes, nose2 *rocks* :)
2013/12/7 Giampaolo Rodola' <g.rodola@gmail.com>:
I just took a look at nosetests. It provides a similar thing and lets you use a regular expression (which indeed makes a lot more sense than using wildcards) It works like this:
nosetests test/test_module -m test_name Check http://pytest.org/latest/usage.html#usage Probably: pytest -k part_of_test_name is what You are seeking.
If You have a while - please look deeper on pytest - it's really powerful/user friendly tool.
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
participants (4)
-
Barry Warsaw
-
Giampaolo Rodola'
-
Piotr Skamruk
-
Terry Reedy