From 437c1860df416e3bbbfab49aefea289e3c4b3ad5 Mon Sep 17 00:00:00 2001 From: fsantos Date: Thu, 14 Mar 2013 15:04:22 +0000 Subject: [PATCH] Monkey patched TestLoader into loading all tests to fix #15 --- django_nose/__init__.py | 4 ++++ django_nose/loader.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 django_nose/loader.py diff --git a/django_nose/__init__.py b/django_nose/__init__.py index 417ffde..aee5a63 100644 --- a/django_nose/__init__.py +++ b/django_nose/__init__.py @@ -7,3 +7,7 @@ # Django < 1.2 compatibility. run_tests = run_gis_tests = NoseTestSuiteRunner + + +# Replace the default test loader. +import django_nose.loader \ No newline at end of file diff --git a/django_nose/loader.py b/django_nose/loader.py new file mode 100644 index 0000000..023f3a7 --- /dev/null +++ b/django_nose/loader.py @@ -0,0 +1,20 @@ +from nose.util import tolist +from nose.loader import defaultTestLoader + + +def loadTestsFromDirMonkeyPatch(test_loader, path): + """ + Monkey patch for TestLoader.loadTestsFromDir. The original + function is a generator but we want tests to be loaded upfront + in order to fix https://github.com/jbalogh/django-nose/issues/15 + and a generator is not compatible with that. + + """ + + return list(test_loader._originalLoadTestsFromDir(path)) + + +if not hasattr(defaultTestLoader, '_originalLoadTestsFromDir'): + defaultTestLoader._originalLoadTestsFromDir = ( + defaultTestLoader.loadTestsFromDir) + defaultTestLoader.loadTestsFromDir = loadTestsFromDirMonkeyPatch