Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62455

Re: Struggling with unittest discovery - how to structure my project test suite

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Struggling with unittest discovery - how to structure my project test suite
Date 2013-12-20 16:48 -0500
References <8607d86e-8fcf-41ac-8da2-a8c137afe087@googlegroups.com> <l91vg9$807$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.4444.1387576123.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/20/2013 12:41 PM, Serhiy Storchaka wrote:
> 20.12.13 16:47, Paul Moore написав(ла):
>> What's the best way of structuring my projects so that:

It depends on your tradeoff between extra setup in the files and how 
much you type each time you run tests.

>> 1. I can run all the tests easily on demand.

I believe that if you copy Lib/idlelib/idle_test/__init__.py to 
tests/__main__.py and add
   import unittest; unittest.main()
then
   python -m tests
would run all your tests. Lib/idlelib/idle_test/README.py may help explain.

>> 2. I can run just the functional or unit tests when needed.
>
> python -m unittest discover -s tests/functional
> python -m unittest discover tests/functional

Ditto for __main__.py files in each, so
   python -m tests.unit (functional)
will work.

>> 3. I can run individual tests (or maybe just individual test modules,
>> I don't have so many tests yet that I know how detailed I'll need to
>> get!) without too much messing (and certainly without changing any
>> source files!)
>
> python -m unittest discover -s tests/functional -p test_spam.py
> python -m unittest discover tests/functional -p test_spam.py
> python -m unittest discover tests/functional test_spam.py

'discover' is not needed for single files.  For instance,
   python -m unittest idlelib.idle_test.test_calltips
works for me. One can extend that to test cases and methods.
python -m unittest idlelib.idle_test.test_calltips.Get_entityTest
and
python -m unittest 
idlelib.idle_test.test_calltips.Get_entityTest.test_bad_entity

If you add to each test_xyz.py file
   if __name__ == '__main__':
     unittest.main(verbosity=2)  # example of adding fixed option
then
   python -m tests.unit.test_xyz
will run the tests in that file. (So does F5 in an Idle editor, which is 
how I run individual test files while editing. I copy the  boilerplate 
from README.txt or an existing test_xyz.py file.)

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Struggling with unittest discovery - how to structure my project test suite Paul  Moore <p.f.moore@gmail.com> - 2013-12-20 06:47 -0800
  Re: Struggling with unittest discovery - how to structure my project test suite Serhiy Storchaka <storchaka@gmail.com> - 2013-12-20 19:41 +0200
    Re: Struggling with unittest discovery - how to structure my project test suite Paul  Moore <p.f.moore@gmail.com> - 2013-12-20 13:02 -0800
  Re: Struggling with unittest discovery - how to structure my project test suite Terry Reedy <tjreedy@udel.edu> - 2013-12-20 16:48 -0500

csiph-web