Ejemplo n.º 1
0
    def load_suites(self, path, recursive=True, merge_suites=False):
        """
        Auto load suites. Path can be package or simple dir.

        :param path: path to suites dir
        :type path: str

        :param recursive: recursive load from path or load from simple dir
        :type recursive: bool

        :param merge_suites: merge suites from sub application
         to self context. for master application only.
        :type merge_suites: bool
        """
        if path not in sys.path:
            sys.path.append(path)

        if recursive:
            suites = loader.load_suites_from_path(path)
        else:
            suites = loader.load_suites_from_dir(path)

        self.register_suites(suites)

        if merge_suites:
            merge_context(self, merge_suites=True)
Ejemplo n.º 2
0
    def __init__(self,
                 name,
                 argv=None,
                 exit=True,
                 config=None,
                 plugins=None,
                 context=None,
                 sub_apps=None,
                 suites_path=None,
                 is_sub_app=False):
        """
        :param name: application name.
        application name is prefix to suite name.
         namespace pattern: <application_name>.<suite_name>:<test_case_name>

        for example:

            >>> from noseapp import Suite

            >>> app = NoseApp('my_app')
            >>> suite = Suite('my_suite')
            >>> suite.name
            >>> 'my_suite'

            >>> app.register_suite(suite)
            >>> suite.name
            >>> 'my_app.my_suite'

        :type name: str

        :param argv: argv to sys.argv
        :type argv: list

        :param exit: do exit after run?
        :type exit: bool

        :param config: import path or absolute file path
        for example:
            * config='project.etc.config'
            * config='/home/user/project/etc/config.py'
        :type config: str

        :param plugins: plugins instances
        :type plugins: list or tuple

        :param context: inctance of AppContext.
         you can create own context instance to run.
        :type context: noseapp.app.context.AppContext

        :param suites_path: path to directory where contains suites
        :type suites_path: str

        :param is_sub_app: is application a sub application?
        :type is_sub_app: bool

        :param sub_apps: sub application instances. for master application only.
        :type sub_apps: list or tuple
        """
        if sub_apps and is_sub_app:
            raise RuntimeError(
                '"{}" can not be maser app. The application is sub app.'.format(self),
            )

        # Initialization config storage
        self.config = self.config_class.from_path(
            get_config_path_by_env(CONFIG_CHECKOUT_ENV, config),
        )

        # Application name. Must be str only.
        self.__name = name

        # Command line options. Will be set after test program initialization.
        self.__options = None

        # If app is sub app that's True else False
        self.__is_sub_app = is_sub_app

        # Sub application list
        self.__sub_apps = list(sub_apps or [])

        # Context will be inject to nose suite
        self.__context = context or AppContext()

        # Add callbacks to context
        self.__context.add_setup(lambda: self.setUp())
        self.__context.add_teardown(lambda: self.tearDown())

        # Saved support nose plugins and add supported self plugins.
        self.__context.plugins.extend(list(plugins or []))

        if self.is_master_app:
            # Default plugins for master app only
            self.__context.plugins.extend(DEFAULT_PLUGINS)
            # Merge context of sub applications
            merge_context(self,
                          merge_setup=True,
                          merge_suites=True,
                          merge_plugins=True,
                          merge_teardown=True)
            # Program object initialization. Will be run later.
            self.__test_program = self.program_class(self, argv=argv, exit=exit)

            # If we are having path to suites then make load suites
            if suites_path is not None:
                self.load_suites(suites_path)