jezdez / django-discover-runner

A Django test runner based on unittest2's test discovery.
http://pypi.python.org/pypi/django-discover-runner
Other
132 stars 13 forks source link

Specifying individual test methods #2

Closed lorin closed 12 years ago

lorin commented 12 years ago

Is it possible to specify individual test methods on the command line? If I try it like this:

python manage.py test myapp.tests.MyTestClass.test_my_method

Then I get an error like this:

TypeError: unbound method test_my_method() must be called with MyTestClass instance as first argument (got nothing instead)
niwinz commented 12 years ago

I'm researching and I can not find a solution. Is there any workaround?

niwinz commented 12 years ago

I think I found the reason for this failure. I think it's a bug in import of class when you're in python2.7, or have installed unittest2 module.

See the file in the line 128 on https://github.com/django/django/blob/master/django/utils/unittest/loader.py:

case.TestCase refers to django.utils.unittest.case.TestCase but, django.test.TestCase is inherit from django.utils.unittest.TestCase.

On python2.7, or with unittest2 installed, django.utils.unittest.TestCase is not the same class as django.utils.unittest.case.TestCase. Because on django.utils.unittest.__init__ if unittest2 module is instaled or your are use python2.7, imports original clases.

For this reason, the condition is not met the line 126 and can not run a particular method of a testcase.

jezdez commented 12 years ago

I can reproduce the errors and could work around it for now by doing this:

from django.utils.unittest.case import TestCase as BaseTestCase
from django.test import TestCase

class MyTestCase(BaseTestCase, TestCase):
    # whatever
jezdez commented 12 years ago

Let me know if that fixes it for you, too.

lorin commented 12 years ago

Confirmed, this resolves my issue. Thanks for the fix.