Skip to content

Latest commit

 

History

History
63 lines (40 loc) · 1.54 KB

40_solution.md

File metadata and controls

63 lines (40 loc) · 1.54 KB

It's easy to change.

  • unittest2 discovery
  • TEST_RUNNER setting

.notes The hipsters like nose or py.test, but unittest2 gets the job done.

@@@ python
class DiscoveryRunner(DjangoTestSuiteRunner):
    """A test suite runner using unittest2 discovery."""
    def build_suite(self, test_labels, **kwargs):

        suite = None
        discovery_root = settings.TEST_DISCOVERY_ROOT

        if test_labels:
            suite = defaultTestLoader.loadTestsFromNames(
                test_labels)

        if suite is None:
            suite = defaultTestLoader.discover(
                discovery_root,
                top_level_dir=settings.BASE_PATH,
                )

        return reorder_suite(suite, (TestCase,))

.notes (Enhanced version in the code online with the slides.)

settings.py

@@@ python
import os.path

BASE_PATH = os.path.dirname(os.path.dirname(__file__))

TEST_DISCOVERY_ROOT = os.path.join(BASE_PATH, "tests")

TEST_RUNNER = "tests.runner.DiscoveryRunner"

\o/

  • Discovers tests wherever you want them.
  • Doesn't run tests from external apps by default.
  • Flexible specification of specific tests to run: Python dotted path to test module, not Django app label.
  • ./manage.py test tests.quotes.test_views

Maybe in 1.5?

.notes django-nose is good too, but this could actually go in Django.