Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#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)

django-management-test-multifile-tests.patch (4.1 KB ) - added by Evgeny Sizikov 16 years ago.
multi-file test suites support for Django management infrastructure
django-management-test_multiple-testcases-per-model.patch (5.6 KB ) - added by Evgeny Sizikov 15 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 Evgeny Sizikov 15 years ago.

Download all attachments as: .zip

Change History (8)

by Evgeny Sizikov, 16 years ago

multi-file test suites support for Django management infrastructure

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: wontfix
Status: newclosed

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 Evgeny Sizikov, 16 years ago

milestone: 1.0 beta
Resolution: wontfix
Status: closedreopened

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 Michael Radziej, 16 years ago

milestone: post-1.0
Resolution: wontfix
Status: reopenedclosed

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 by (none), 15 years ago

milestone: post-1.0

Milestone post-1.0 deleted

by Evgeny Sizikov, 15 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.

comment:5 by Evgeny Sizikov, 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, defaultTestLoader
    3 
    4 import test_email_validation, test_highlight, test_phone_number_normalization, test_views
    5 
    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 s
    18 
    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  
    11# -*- coding: utf-8 -*-
    22import re
    3 from unittest import main, makeSuite, TestSuite, TestCase
     3from unittest import TestCase
    44
    55EMAIL_VALIDATION = re.compile(r"^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@"
    66                               "([a-z0-9_]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]{1,64})*\."
    77                               "(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|"
    88                               "[a-z][a-z])|"
    99                               "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$",
    1010                               re.I | re.U)
    1111from django.forms.fields import email_re as EMAIL_VALIDATION
    local@SecondLevelDomainNamesAreInvalidIf  
    219219       
    220220    def _test_email_invalid_19(self):
    221221        email = r'local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'
    222222        self.failIf(self.re.match(email), email + r' invalid')
    223223       
    224224    def _test_email_invalid_20(self):
    225225        email = r'local@thirdLevel.SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'
    226226        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 s
    234 
    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  
    11# -*- coding: utf-8 -*-
    22import re
    3 from unittest import main, makeSuite, TestSuite, TestCase
     3from unittest import TestCase
    44
    55from bis.refs.utils import highlight
    66
    77
    88class SearchHighlightTests(TestCase):
    99    """ Search results highlighting.
    1010   
    1111http://trac.223-223.ru/bis/ticket/75
    http://trac.223-223.ru/bis/ticket/75  
    3535       
    3636    def test_highlight_4(self):
    3737        res = self._highlight(u'лиса123', u'лис')
    3838        self.assertEqual(res, u'<b>лиса</b>123')
    3939       
    4040    def test_highlight_5(self):
    4141        res = self._highlight(u'Насос Ручеек - продажа', u'насос')
    4242        self.assertEqual(res, u'<b>Насос</b> Ручеек - продажа')
    43 
    44 
    45 def suite():
    46     s = TestSuite()
    47     s.addTest(makeSuite(SearchHighlightTests))
    48     return s
    49 
    50 
    51 if __name__ == '__main__':
    52     main(defaultTest='suite')
Note: See TracTickets for help on using tickets.
Back to Top