#8010 closed (wontfix)
adding support for multiple test files for applications
Reported by: | Evgeny Sizikov | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It would be very handy for a complex applications if Django 1.0 would support not a single 'tests.py' unit test file, but multi-file test suites like:
app2/ tests.py ... app3/tests/ test_simple.py test_connect.py test_utils.py ...
I've made a fast and dirty support for such a thing (please see patch attached).
Attachments (3)
Change History (8)
by , 16 years ago
Attachment: | django-management-test-multifile-tests.patch added |
---|
comment:1 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This patch forces a particular naming convention on people which isn't very nice. It also doesn't really add an functionality that isn't already possible. You can already put as many tests as you like in a tests/
directory and set up how to run them via the __init__.py
file (using the normal __test__
attribute from the doctest module, for example), with no restrictions on naming conventions.
comment:2 by , 16 years ago
milestone: | 1.0 beta |
---|---|
Resolution: | wontfix |
Status: | closed → reopened |
Usage of 'test_' prefix for unit tests files is just an initial implementation option.
You could set the glob mask to something like '[_]*.py' in order to get all python modules beside init.py[co] files, or something like that.
The main idea was to allow developers to split big sized tests.py into several files without requiring to manually enumerate created files in the init.py, and I do think it worth considering.
comment:3 by , 16 years ago
milestone: | → post-1.0 |
---|---|
Resolution: | → wontfix |
Status: | reopened → closed |
Please don't reopen tickets that were closed by a core developer with 'wontfix'. If you want to discuss, please send a message to django-developers.
by , 15 years ago
Attachment: | django-management-test_multiple-testcases-per-model.patch added |
---|
Updated after Django 1.1 release. Introduced TEST_MODULES_GLOB option inside the global_settings.py to allow user to override the naming convention used for the test files search.
by , 15 years ago
Attachment: | django-management-test_multiple-testcases-per-model.2.patch added |
---|
comment:5 by , 15 years ago
After applying the patch I have got a considerable simplification of an application test cases (see the diff below).
As you can see I kept suite() method for one test group, test_phone_numbers.py - this demonstrates that the default behaviour keeps working. But, after applying the patch I can call the "disabled" use case easily (while getting a lot of test failures -the reason of disabling the test case):
$ python manage.py test refs.PhoneNumberNormalizationTests
Following is the diff which demonstrates test suite simplification changes geared by the patch:
-
bis/refs/tests/__init__.py
diff --git a/bis/refs/tests/__init__.py b/bis/refs/tests/__init__.py
a b 1 # -*- coding: utf-8 -*-2 from unittest import main, TestSuite, defaultTestLoader3 4 import test_email_validation, test_highlight, test_phone_number_normalization, test_views5 6 7 test_suites = [test_email_validation.suite(),8 test_highlight.suite(),9 test_phone_number_normalization.suite(),10 test_views.suite(),11 ]12 13 14 def suite():15 s = TestSuite()16 s.addTests(test_suites)17 return s18 19 20 if __name__ == '__main__':21 main(defaultTest='suite') -
bis/refs/tests/test_email_validation.py
diff --git a/bis/refs/tests/test_email_validation.py b/bis/refs/tests/test_email_validation.py
a b 1 1 # -*- coding: utf-8 -*- 2 2 import re 3 from unittest import main, makeSuite, TestSuite,TestCase3 from unittest import TestCase 4 4 5 5 EMAIL_VALIDATION = re.compile(r"^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@" 6 6 "([a-z0-9_]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]{1,64})*\." 7 7 "(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|" 8 8 "[a-z][a-z])|" 9 9 "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$", 10 10 re.I | re.U) 11 11 from django.forms.fields import email_re as EMAIL_VALIDATION … … local@SecondLevelDomainNamesAreInvalidIf 219 219 220 220 def _test_email_invalid_19(self): 221 221 email = r'local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org' 222 222 self.failIf(self.re.match(email), email + r' invalid') 223 223 224 224 def _test_email_invalid_20(self): 225 225 email = r'local@thirdLevel.SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org' 226 226 self.failIf(self.re.match(email), email + r' invalid') 227 228 229 def suite():230 s = TestSuite()231 s.addTest(makeSuite(EmailValidatorValidTests))232 s.addTest(makeSuite(EmailValidatorInvalidTests))233 return s234 235 236 if __name__ == '__main__':237 main(defaultTest='suite') -
bis/refs/tests/test_highlight.py
diff --git a/bis/refs/tests/test_highlight.py b/bis/refs/tests/test_highlight.py
a b 1 1 # -*- coding: utf-8 -*- 2 2 import re 3 from unittest import main, makeSuite, TestSuite,TestCase3 from unittest import TestCase 4 4 5 5 from bis.refs.utils import highlight 6 6 7 7 8 8 class SearchHighlightTests(TestCase): 9 9 """ Search results highlighting. 10 10 11 11 http://trac.223-223.ru/bis/ticket/75 … … http://trac.223-223.ru/bis/ticket/75 35 35 36 36 def test_highlight_4(self): 37 37 res = self._highlight(u'лиса123', u'лис') 38 38 self.assertEqual(res, u'<b>лиса</b>123') 39 39 40 40 def test_highlight_5(self): 41 41 res = self._highlight(u'Насос Ручеек - продажа', u'насос') 42 42 self.assertEqual(res, u'<b>Насос</b> Ручеек - продажа') 43 44 45 def suite():46 s = TestSuite()47 s.addTest(makeSuite(SearchHighlightTests))48 return s49 50 51 if __name__ == '__main__':52 main(defaultTest='suite')
multi-file test suites support for Django management infrastructure