Hello all.
I've been using the built in django testing framework for my code. But
as I add more and more tests, I'm finding the standard behavior of
only looking for tests in models.py and tests.py to be a little
unwieldy. I'd prefer to organize my tests in separate files. I made
changes to the end of django/test/simple.py (function build_suite) to
also search all modules in the "tests" subdirectory of the app. I like
it better, perhaps other people would agree.

I haven't contributed anything before, so if there is a better way to
go about this than I am, please let me know.

Thanks,
sean

----------------------------------
django/test/simple.py
----------------------------------
def build_suite(app_module):
    .
    .snip
    .
    except ImportError, e:
        .
        .snip
        .
    # and try to import any test modules from the TEST_MODULE
subdirectory if it exists
    import os, os.path
    try:
        dir = os.path.join(os.getcwd(), app_path[-1], TEST_MODULE)
        for submodule in os.listdir(dir):
            try:
                name_tuple = os.path.splitext(submodule)
                if name_tuple[1] == '.py' and name_tuple[0] !=
'__init__':
                    module_name = '.'.join(app_path + [TEST_MODULE] +
[name_tuple[0]])
                    test_module = __import__(module_name, {}, {},
name_tuple[0])
 
suite.addTest(unittest.defaultTestLoader.loadTestsFromModule(test_module))
                    try:
 
suite.addTest(doctest.DocTestSuite(test_module,
checker=doctestOutputChecker, runner=DocTestRunner))
                    except ValueError:
                        # no doctests
                        pass
            except ImportError, e:
                # not a valid module, skip
                pass
    except Exception:
        # couldn't find a tests subdirectory
        pass

    return suite


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to