-
-
Save thachhoang/8885808 to your computer and use it in GitHub Desktop.
Revisions
-
carljm revised this gist
May 14, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ class DiscoveryRunner(DjangoTestSuiteRunner): """A test suite runner that uses unittest2 test discovery.""" def build_suite(self, test_labels, extra_tests=None, **kwargs): suite = None -
Carl Meyer revised this gist
Mar 14, 2012 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,8 @@ package, and that package does not itself directly contain any tests, it'll do test discovery in all sub-modules of that package. This code doesn't modify the default unittest2 test discovery behavior, which only searches for tests in files named "test*.py". """ from django.conf import settings -
Carl Meyer revised this gist
Mar 14, 2012 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,8 @@ package, and that package does not itself directly contain any tests, it'll do test discovery in all sub-modules of that package. This code doesn't modify the default unittest2 test discovery behavior, which only searches for tests in files named "test*.py". """ from django.conf import settings from django.test import TestCase -
carljm revised this gist
Mar 13, 2012 . 2 changed files with 26 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,14 @@ a base path specified in settings, rather than requiring all tests to be in ``tests`` module of an app. If you just run ``./manage.py test``, it'll discover and run all tests underneath the ``TEST_DISCOVERY_ROOT`` setting (a path). If you run ``./manage.py test full.dotted.path.to.test_module``, it'll run the tests in that module (you can also pass multiple modules). And (new in this updated version), if you give it a single dotted path to a package, and that package does not itself directly contain any tests, it'll do test discovery in all sub-modules of that package. """ from django.conf import settings This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,31 @@ """ You need the ``BASE_PATH`` and ``TEST_DISCOVERY_ROOT`` settings in order for this test runner to work. ``BASE_PATH`` should be the directory containing your top-level package(s); in other words, the directory that should be on ``sys.path`` for your code to import. This is the directory containing ``manage.py`` in the new Django 1.4 project layout. ``TEST_DISCOVERY_ROOT`` should be the root directory to discover tests within. You could make this the same as ``BASE_PATH`` if you want tests to be discovered anywhere in your project. If you want tests to only be discovered within, say, a top-level ``tests`` directory, you'd set ``TEST_DISCOVERY_ROOT`` as shown below. And you need to point the ``TEST_RUNNER`` setting to the ``DiscoveryRunner`` class above. """ import os.path # This is correct for the Django 1.4-style project layout; for the old-style # project layout with ``settings.py`` and ``manage.py`` in the same directory, # you'd want to only call ``os.path.dirname`` once. BASE_PATH = os.path.dirname(os.path.dirname(__file__)) # This would be if you put all your tests within a top-level "tests" package. TEST_DISCOVERY_ROOT = os.path.join(BASE_PATH, "tests") # This assumes you place the above ``DiscoveryRunner`` in ``tests/runner.py``. TEST_RUNNER = "tests.runner.DiscoveryRunner" -
Carl Meyer revised this gist
Mar 13, 2012 . 2 changed files with 46 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,39 @@ """ An alternative Django ``TEST_RUNNER`` which uses unittest2 test discovery from a base path specified in settings, rather than requiring all tests to be in ``tests`` module of an app. If you just run ``./manage.py test``, it'll discover and run all tests underneath the ``TEST_DISCOVERY_ROOT`` setting (a path). If you run ``./manage.py test full.dotted.path.to.test_module``, it'll run the tests in that module (you can also pass multiple modules). And (new in this updated version), if you give it a single dotted path to a package, and that package does not itself directly contain any tests, it'll do test discovery in all sub-modules of that package. """ from django.conf import settings from django.test import TestCase from django.test.simple import DjangoTestSuiteRunner, reorder_suite from django.utils.importlib import import_module from django.utils.unittest.loader import defaultTestLoader class DiscoveryDjangoTestSuiteRunner(DjangoTestSuiteRunner): """A test suite runner that uses unittest2 test discovery.""" def build_suite(self, test_labels, extra_tests=None, **kwargs): suite = None discovery_root = settings.TEST_DISCOVERY_ROOT if test_labels: suite = defaultTestLoader.loadTestsFromNames(test_labels) # if single named module has no tests, do discovery within it if not suite.countTestCases() and len(test_labels) == 1: suite = None discovery_root = import_module(test_labels[0]).__path__[0] if suite is None: suite = defaultTestLoader.discover( discovery_root, top_level_dir=settings.BASE_PATH, ) if extra_tests: for test in extra_tests: This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ """ You need the ``BASE_PATH`` and ``TEST_DISCOVERY_ROOT`` settings in order for this test runner to work. ``BASE_PATH`` should be the directory containing your top-level package(s); in other words, the directory that should be on ``sys.path`` for your code to import. This is the directory containing ``manage.py`` in the new Django 1.4 project layout. ``TEST_DISCOVERY_ROOT`` should be the root directory to discover tests within. You could make this the same as ``BASE_PATH`` if you want tests to be discovered anywhere in your project. If you want tests to only be discovered within, say, a top-level ``tests`` directory, you'd set ``TEST_DISCOVERY_ROOT`` as shown below. And you need to point the ``TEST_RUNNER`` setting to the ``DiscoveryRunner`` class above. """ import os.path # This is correct for the Django 1.4-style project layout; for the old-style project layout # with ``settings.py`` and ``manage.py`` in the same directory, you'd want to only call # ``os.path.dirname`` once. BASE_PATH = os.path.dirname(os.path.dirname(__file__)) # This would be if you put all your tests within a top-level "tests" package. TEST_DISCOVERY_ROOT = os.path.join(BASE_PATH, "tests") # And this assumes you place the above ``DiscoveryRunner`` in ``tests/runner.py``. TEST_RUNNER = "tests.runner.DiscoveryRunner" -
Carl Meyer revised this gist
Dec 9, 2011 . No changes.There are no files selected for viewing
-
Carl Meyer created this gist
Dec 9, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ from django.conf import settings from django.test.simple import DjangoTestSuiteRunner, reorder_suite from django.utils.unittest import TestCase from django.utils.unittest.loader import defaultTestLoader class DiscoveryDjangoTestSuiteRunner(DjangoTestSuiteRunner): def build_suite(self, test_labels, extra_tests=None, **kwargs): if test_labels: suite = defaultTestLoader.loadTestsFromNames(test_labels) else: suite = defaultTestLoader.discover(settings.TEST_DISCOVERY_ROOT) if extra_tests: for test in extra_tests: suite.addTest(test) return reorder_suite(suite, (TestCase,))