views:

22

answers:

1

I have some methods written into a django.test.TestCase object that I'd like to run from the manage.py shell on my real database. But when I try to instantiate the TestCase object to run the test method, I get this error:

ValueError: no such test method in <class 'track.tests.MentionTests'>: runTest

Is there a way to instantiate the TestCase objects? Or is there a way to run a test method against a non-test database?

A: 

From the Django testing docs:

Running tests

Once you've written tests, run them using the test subcommand of your project's manage.py utility:

$ ./manage.py test

By default, this will run every test in every application in INSTALLED_APPS. If you only want to run tests for a particular application, add the application name to the command line. For example, if your INSTALLED_APPS contains 'myproject.polls' and 'myproject.animals', you can run the myproject.animals unit tests alone with this command:

$ ./manage.py test animals

Note that we used animals, not myproject.animals. New in Django 1.0: You can now choose which test to run.

You can be even more specific by naming an individual test case. To run a single test case in an application (for example, the AnimalTestCase described in the "Writing unit tests" section), add the name of the test case to the label on the command line:

$ ./manage.py test animals.AnimalTestCase

And it gets even more granular than that! To run a single test method inside a test case, add the name of the test method to the label:

$ ./manage.py test animals.AnimalTestCase.testFluffyAnimals

The last example should be applicable in your case.

If this is what you are doing, you'll need to post a more detailed description of the code employed in your test case.

Martin Eve
Sure, but that creates a new test database to run against. How do I run it against the main (non-test) database?
Leopd