0

I'm having trouble creating a test suite in Django 1.3.

Say I have an installed app in a directory called app_name. One of the files in that directory is foo.py which defines a class named Foo. I want to test that, so I also have a file that directory called foo_test.py which defines a class named FooTest. That file looks like:

import unittest
import foo

class FooTest(unittest.TestCase):
  def setUp(self):
    self.foo_instance = foo.Foo()

  ... etc

Now down the line I'll have other test cases in other files, and I'll want to run them all as part of a test suite. So in the same directory app_name I created a file tests.py which will define the suite. At first I defined it like:

import foo_test

from django.test.simple import DjangoTestSuiteRunner

def suite():
  runner = DjangoTestSuiteRunner()
  return runner.build_suite(['app_name'])

Unfortunately, this fails because calling runner.build_suite(['app_name']) searches app_name for a tests.py file, executes suite(), and this continues recursively until the Python interpreter stops everything for exceeding the maximum recursion depth.

Changing runner.build_suite(['app_name']) to

runner.build_suite(['app_name.foo_test'])

or

runner.build_suite(['app_name.foo_test.FooTest'])

leads to errors like ValueError: Test label 'app_name.foo_test' does not refer to a test.

And changing it to:

runner.build_suite(['foo_test'])

or

runner.build_suite(['foo_test.FooTest'])

leads to errors like App with label foo_test could not be found.

I'm kind of out of ideas at this point. Any help would be very much appreciated. Thanks!

shadowmatter
  • 1,292
  • 1
  • 18
  • 30

1 Answers1

0

See the Python documentation for organizing tests, and use one of the alternative methods there to build your test suite. Incidentally, none of the recommended methods employ build_suite.

Chris Pratt
  • 207,690
  • 31
  • 326
  • 382