#17365: Extend test discovery to include unittest2 test suite runner
-----------------------------------+------------------------------------
     Reporter:  jezdez             |                    Owner:  myusuf3
         Type:  New feature        |                   Status:  new
    Component:  Testing framework  |                  Version:  master
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Accepted
    Has patch:  1                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+------------------------------------

Comment (by prestontimmons):

 I thought I'd give this a shot.

 Here's an up-to-date branch based on carljm's one.

 https://github.com/prestontimmons/django/tree/ticket-17365

 And the commit:

 
https://github.com/prestontimmons/django/commit/68142a4ef14a5bcf7938eaa7279373ebd2de1ca1

 I added tests for these cases:

 {{{
 # Discover tests under current directory
 python manage.py test

 # Test under different root
 python manage.py test root="../tests

 # Test with top level
 python manage.py test --root="../tests --top_level=../../top

 # Use different pattern
 python manage.py test --pattern="tests_*"

 # Test single installed app with discovery
 python manage.py test contact

 # Test multiple apps with discovery
 python manage.py test myapp1 myapp2 myapp3

 # Test specific test module
 python manage.py test myapp1.tests_views
 python manage.py test myapp1.test_models

 # Test with mixed arguments
 python manage.py test myapp.test_views myapp.test_models

 # Test single testcase
 python manage.py test contact.tests.ContactTest

 # Test single method
 python manage.py test contact.tests.ContactTest.test_contact

 # Test all installed apps with discovery
 python manage.py test --installed
 }}}


 == Notes: ==

 In this branch, the ''django.test.simple.DjangoTestSuiteRunner'' is still
 the default. Users have to opt-in to the DiscoverRunner.

 This means the old style tests are default unless a user updates their
 testrunner setting to ''django.test.runner.DiscoverRunner''.


 == Doctest support: ==

 Is the plan to do a hard cut-off of doctest support?

 For instance, the page below introduces the user to both at the start. I
 started in on some docs, but not sure if I should retrofit the existing
 docs, or do a deeper restructure.

 https://docs.djangoproject.com/en/dev/topics/testing/

 If we do a restructure, it needs to be clear to the user that they must
 manually update their `TEST_RUNNER` setting to use the new discovery
 tests.


 == Backward-incompatibility ==

 As decided, the new runner won't support doctests or tests in models.py.

 A more subtle change is that the discover runner won't run tests specified
 in an __init__.py of the tests module, like this:

 {{{
 myapp/
     tests/
         __init__.py
 }}}

 That won't match a discovery pattern.

 The unittest docs cover this in detail here:

 http://docs.python.org/2/library/unittest.html#load-tests-protocol

 I don't think it's a big issue, because most times the __init__.py is only
 set up to import from other test files. If those other files are named
 "tests*.py", then they will be found automatically.

 It's worth a note in the docs somewhere for those migrating.


 == Caveats: ==

 I ran into problems with dotted paths to a method on a TestCase.

 Whether using ''django.test.TestCase'', or
 ''django.utils.unittest.TestCase'', this line always returned False.

 {{{
     issubclass(parent, case.TestCase)
 }}}

 
https://github.com/prestontimmons/django/commit/68142a4ef14a5bcf7938eaa7279373ebd2de1ca1#L4R125

 This caused the methods to be called wrong.

 For some reason, this fixed it. I don't know the reason why.

 {{{
     issubclass(parent, unittest.TestCase)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/17365#comment:40>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to