Merge pull request #135 from gregmuellegger/runtests-args

Allow runtests.py to take positional arguments to specify only a subset of tests to run.
This commit is contained in:
Daniel Greenfeld 2013-05-23 13:27:16 -07:00
commit 1e1f101397
2 changed files with 43 additions and 3 deletions

View file

@ -142,6 +142,21 @@ For now, we use the Django Test framework (based on unittest).
Also, keep your tests as simple as possible. Complex tests end up requiring their own tests. We would rather see duplicated assertions across test methods then cunning utility methods that magically determine which assertions are needed at a particular stage. Remember: `Explicit is better than implicit`.
You don't need to run the whole test suite during development in order to make
the test cycles a bit faster. Just pass in the specific tests you want to run
to ``runtests.py`` as you would do with the ``django-admin.py test`` command.
Examples::
# only run the tests from application ``blog``
python runtests.py blog
# only run testcase class ``Admin2Test`` from app ``djadmin2``
python runtests.py djadmin2.Admin2Test
# run all tests from application ``blog`` and the test named
# ``test_register`` on the ``djadmin2.Admin2Test`` testcase.
python runtests.py djadmin2.Admin2Test.test_register blog
Don't mix code changes with whitespace cleanup
----------------------------------------------

View file

@ -10,11 +10,36 @@ from django.test.utils import get_runner
from django.conf import settings
def runtests():
def runtests(tests=('blog', 'djadmin2',)):
'''
Takes a list as first argument, enumerating the apps and specific testcases
that should be executed. The syntax is the same as for what you would pass
to the ``django-admin.py test`` command.
Examples::
# run the default test suite
runtests()
# only run the tests from application ``blog``
runtests(['blog'])
# only run testcase class ``Admin2Test`` from app ``djadmin2``
runtests(['djadmin2.Admin2Test'])
# run all tests from application ``blog`` and the test named
# ``test_register`` on the ``djadmin2.Admin2Test`` testcase.
runtests(['djadmin2.Admin2Test.test_register', 'blog'])
'''
TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=1, interactive=True)
failures = test_runner.run_tests(['blog', 'djadmin2'])
failures = test_runner.run_tests(tests)
sys.exit(bool(failures))
if __name__ == '__main__':
runtests()
if len(sys.argv) > 1:
tests = sys.argv[1:]
runtests(tests)
else:
runtests()