示例#1
0
def _initialize_logging():
    """
    Sets up a log file for the unit tests and optionally logs everything to the
    console.
    """
    import tank

    tank.LogManager().initialize_base_file_handler("tk-test")
    tank.LogManager().initialize_custom_handler()
    print("Logs for this test run can be found at", tank.LogManager().log_file)
示例#2
0
def _initialize_logging(log_to_console):
    """
    Sets up a log file for the unit tests and optionally logs everything to the console.

    :param log_to_console: If True, all Toolkit logging will go to the console.
    """
    import tank
    tank.LogManager().initialize_base_file_handler("run_tests")

    if options.log_to_console:
        tank.LogManager().initialize_custom_handler()
示例#3
0
def _initialize_logging():
    """
    Sets up a log file for the unit tests and optionally logs everything to the console.
    """
    import tank
    tank.LogManager().initialize_base_file_handler("run_tests")

    if options.log_to_console:
        tank.LogManager().initialize_custom_handler()

    if options.debug:
        tank.LogManager().global_debug = True
示例#4
0
    def swap_core(cls, core_path):
        """
        Swap the current core with the core located at the supplied path.

        Actually just unloads the existing core and ensures an import handler
        exists that points to the supplied core path. When this method completes,
        all core namespaces will be removed from `sys.modules`.

        :param core_path: The path to the new core to use upon import.
        """
        # make sure handler is up
        handler = cls._initialize()

        log.debug("%s: Begin swapping core to %s" % (handler, core_path))

        # swapping core means our logging singleton will be reset.
        # make sure that there are no log handlers registered
        # and associated with the singleton as these will be lost
        # use local imports to ensure a fresh cut of the code
        from ..log import LogManager
        prev_log_file = LogManager().uninitialize_base_file_handler()
        # logging to file is now disabled and will be renamed after the
        # main tank import of the new code.

        # make sure that this entire operation runs inside the import thread lock
        # in order to not cause any type of cross-thread confusion during the swap
        imp.acquire_lock()

        try:
            handler._swap_core(core_path)

            # because we are swapping out the code that we are currently running, Python is
            # generating a runtime warning:
            #
            # RuntimeWarning: Parent module 'tank.bootstrap' not found while handling absolute import
            #
            # We are fixing this issue by re-importing tank, so it's essentially a chicken and egg
            # scenario. So it's ok to mute the warning. Interestingly, by muting the warning, the
            # execution of the reload/import becomes more complete and it seems some parts of the
            # code that weren't previously reloaded are now covered. So turning off the warnings
            # display seems to have executionary side effects.

            # Save the existing list of warning filters before we modify it using simplefilter().
            # Note: the '[:]' causes a copy of the list to be created. Without it, original_filter
            # would alias the one and only 'real' list and then we'd have nothing to restore.
            original_filters = warnings.filters[:]

            # Ignore all warnings
            warnings.simplefilter("ignore")

            log.debug("...core swap complete.")

            log.debug(
                "running explicit 'import tank' to re-initialize new core...")

            try:
                # Kick toolkit to re-import
                import tank

            finally:
                # Restore the list of warning filters.
                warnings.filters = original_filters

            log.debug("...import complete")

        finally:
            imp.release_lock()

        # and re-init our disk logging based on the new code
        # access it from the new tank instance to ensure we get the new code
        try:
            if prev_log_file:
                tank.LogManager().initialize_base_file_handler_from_path(
                    prev_log_file)
        except AttributeError, e:
            # older versions of the API may not have this defined.
            log.warning(
                "Switching to a version of the core API that doesn't "
                "have a LogManager.initialize_base_file_handler_from_path method defined."
            )
示例#5
0
print ""
print "Adding tank location to python_path: %s" % python_path
sys.path = [python_path] + sys.path

# prepend tank_vendor location to PYTHONPATH to make sure we are running
# the tests against the vendor libs, not local libs on the machine
python_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                           "python"))
print "Adding tests/python location to python_path: %s" % python_path
sys.path = [python_path] + sys.path

import unittest2 as unittest

import tank

tank.LogManager().initialize_base_file_handler("run_tests")


class TankTestRunner(object):
    def __init__(self, test_root=None):

        curr_dir = os.path.dirname(os.path.abspath(__file__))

        if test_root is None:
            self.test_path = curr_dir
        else:
            self.test_path = test_root

        print "Tests will be loaded from: %s" % self.test_path

        # the fixtures are always located relative to the test location