'Sets up the unit-testing environment.
This involves loading modules as if by web2py.
Also we must have a test database.
If testing controllers, tests need to set up the request themselves.'

def loadTestsFromName(self, file_name, discovered):

    if file_name.endswith('.py'):
        test_globals = self.environment
        module_globals = dict(self.environment)
        execfile(file_name, module_globals)
        import inspect
        tests = []
        for (name, thing) in module_globals.iteritems():
            if ((name not in test_globals) or (test_globals[name] is not thing)):
                if (isinstance(thing, type) and issubclass(thing, unittest.TestCase)):
                    for member_name in dir(thing):
                        if member_name.startswith('test'):
                            if callable(getattr(thing, member_name)):
                                tests.append(thing(member_name))
                elif (name.startswith('test') or name.startswith('Test')):
                    if inspect.isfunction(thing):
                        function = thing
                        function_name = name
                        if (function.__module__ in ('__main__', None)):
                            tests.append(nose.case.FunctionTestCase(function))
        return tests
    else:
        return []
