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
--
https://mail.python.org/mailman/listinfo/python-list