Code

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#8010 closed (wontfix)

adding support for multiple test files for applications

Reported by: esizikov Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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)

django-management-test-multifile-tests.patch (4.1 KB) - added by esizikov 6 years ago.
multi-file test suites support for Django management infrastructure
django-management-test_multiple-testcases-per-model.patch (5.6 KB) - added by esizikov 5 years ago.
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.
django-management-test_multiple-testcases-per-model.2.patch (5.7 KB) - added by esizikov 5 years ago.

Download all attachments as: .zip

Change History (8)

Changed 6 years ago by esizikov

multi-file test suites support for Django management infrastructure

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to 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 Changed 6 years ago by esizikov

  • milestone 1.0 beta deleted
  • Resolution wontfix deleted
  • Status changed from closed to 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 Changed 6 years ago by mir

  • milestone set to post-1.0
  • Resolution set to wontfix
  • Status changed from reopened to 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.

comment:4 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

Changed 5 years ago by esizikov

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.

comment:5 Changed 5 years ago by esizikov

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:

diff --git a/bis/refs/tests/__init__.py b/bis/refs/tests/__init__.py
--- a/bis/refs/tests/__init__.py
+++ b/bis/refs/tests/__init__.py
@@ -1,21 +0,0 @@
-# -*- coding: utf-8 -*-
-from unittest import main, TestSuite, defaultTestLoader
-
-import test_email_validation, test_highlight, test_phone_number_normalization, test_views
-
-
-test_suites = [test_email_validation.suite(),
-               test_highlight.suite(),
-               test_phone_number_normalization.suite(),
-               test_views.suite(),
-               ]
-
-
-def suite():
-    s = TestSuite()
-    s.addTests(test_suites)
-    return s
-
-
-if __name__ == '__main__':
-    main(defaultTest='suite')
diff --git a/bis/refs/tests/test_email_validation.py b/bis/refs/tests/test_email_validation.py
--- a/bis/refs/tests/test_email_validation.py
+++ b/bis/refs/tests/test_email_validation.py
@@ -1,11 +1,11 @@
 # -*- coding: utf-8 -*-
 import re
-from unittest import main, makeSuite, TestSuite, TestCase
+from unittest import TestCase
 
 EMAIL_VALIDATION = re.compile(r"^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@"
                                "([a-z0-9_]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]{1,64})*\."
                                "(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|"
                                "[a-z][a-z])|"
                                "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$",
                                re.I | re.U)
 from django.forms.fields import email_re as EMAIL_VALIDATION
@@ -219,19 +219,8 @@ local@SecondLevelDomainNamesAreInvalidIf
         
     def _test_email_invalid_19(self):
         email = r'local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'
         self.failIf(self.re.match(email), email + r' invalid')
         
     def _test_email_invalid_20(self):
         email = r'local@thirdLevel.SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'
         self.failIf(self.re.match(email), email + r' invalid')
-
-
-def suite():
-    s = TestSuite()
-    s.addTest(makeSuite(EmailValidatorValidTests))
-    s.addTest(makeSuite(EmailValidatorInvalidTests))
-    return s
-
-
-if __name__ == '__main__':
-    main(defaultTest='suite')
diff --git a/bis/refs/tests/test_highlight.py b/bis/refs/tests/test_highlight.py
--- a/bis/refs/tests/test_highlight.py
+++ b/bis/refs/tests/test_highlight.py
@@ -1,11 +1,11 @@
 # -*- coding: utf-8 -*-
 import re
-from unittest import main, makeSuite, TestSuite, TestCase
+from unittest import TestCase
 
 from bis.refs.utils import highlight
 
 
 class SearchHighlightTests(TestCase):
     """ Search results highlighting.
     
 http://trac.223-223.ru/bis/ticket/75
@@ -35,18 +35,8 @@ http://trac.223-223.ru/bis/ticket/75
         
     def test_highlight_4(self):
         res = self._highlight(u'лиса123', u'лис')
         self.assertEqual(res, u'<b>лиса</b>123')
         
     def test_highlight_5(self):
         res = self._highlight(u'Насос Ручеек - продажа', u'насос')
         self.assertEqual(res, u'<b>Насос</b> Ручеек - продажа')
-
-
-def suite():
-    s = TestSuite()
-    s.addTest(makeSuite(SearchHighlightTests))
-    return s
-
-
-if __name__ == '__main__':
-    main(defaultTest='suite')

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.