Пример #1
0
    def __init__(self, settings):

        # self.__test_limit = int(kwargs.get("test_multithreading_limit", 1))
        self.__test_limit = settings.test_thread_limit
        if self.__test_limit == 0 or self.__test_limit is None:
            LogJunkie.warn("Thread limit for tests cannot be 0 or None, "
                           "falling back to limit of 1 thread per test case.")
            self.__test_limit = 1

        # self.__suite_limit = int(kwargs.get("suite_multithreading_limit", 1))
        self.__suite_limit = settings.suite_thread_limit
        if self.__suite_limit == 0 or self.__suite_limit is None:
            LogJunkie.warn("Thread limit for suites cannot be 0 or None, "
                           "falling back to limit of 1 thread per test suite.")
            self.__suite_limit = 1

        LogJunkie.debug(
            "=======================Parallel Processor Settings============================="
        )
        LogJunkie.debug(">> Suite level multi-threading enabled: {}".format(
            self.suite_multithreading()))
        LogJunkie.debug(">> Suite level multi-threading limit: {}".format(
            self.__suite_limit))
        LogJunkie.debug(">> Test level multi-threading enabled: {}".format(
            self.test_multithreading()))
        LogJunkie.debug(">> Test level multi-threading limit: {}".format(
            self.__test_limit))
        LogJunkie.debug(
            "==============================================================================="
        )
Пример #2
0
    def run(self, **kwargs):
        """
        Initiates the execution process that runs tests
        :return: None
        """
        self.__settings = Settings(runner_kwargs=self.__kwargs,
                                   run_kwargs=kwargs)
        initial_start_time = time.time()
        resource_monitor = None
        try:
            if self.__settings.monitor_resources:
                resource_monitor = ResourceMonitor()
                resource_monitor.start()
            self.__processor = ParallelProcessor(self.__settings)

            with suppressed_stdout(self.__settings.quiet):
                while self.__suites:
                    for suite in list(self.__suites):
                        suite_object = Builder.get_execution_roster().get(
                            suite, None)
                        if suite_object is not None:
                            if self.__processor.suite_multithreading(
                            ) and suite_object.is_parallelized():
                                while True:
                                    if self.__processor.suite_qualifies(
                                            suite_object):
                                        time.sleep(
                                            Limiter.get_suite_throttling())
                                        self.__executed_suites.append(
                                            suite_object)
                                        ParallelProcessor.run_suite_in_a_thread(
                                            self.__run_suite, suite_object)
                                        self.__suites.remove(suite)
                                        break
                                    elif suite_object.get_priority() is None:
                                        break
                                    else:
                                        time.sleep(1)
                            else:
                                if not suite_object.is_parallelized():
                                    LogJunkie.debug(
                                        "Cant run suite: {} in parallel with any other suites. Waiting for "
                                        "parallel suites to finish so I can run it by itself."
                                        .format(
                                            suite_object.get_class_object()))
                                    ParallelProcessor.wait_currently_active_suites_to_finish(
                                    )
                                self.__executed_suites.append(suite_object)
                                self.__run_suite(suite_object)
                                self.__suites.remove(suite)
                        else:
                            LogJunkie.warn(
                                "Suite: {} not found! Make sure that your input is correct. "
                                "If it is, make sure the use of Test Junkie's decorators "
                                "is correct.".format(suite))
                            self.__suites.remove(suite)
                    LogJunkie.debug("{} Suite(s) left in queue.".format(
                        len(self.__suites)))
                    time.sleep(0.2)

                ParallelProcessor.wait_currently_active_suites_to_finish()
        finally:
            if self.__settings.monitor_resources:
                resource_monitor.shutdown()

        runtime = time.time() - initial_start_time
        print("========== Test Junkie finished in {:0.2f} seconds ==========".
              format(runtime))
        aggregator = Aggregator(self.get_executed_suites())
        Aggregator.present_console_output(aggregator)
        if self.__settings.html_report:
            reporter = Reporter(
                monitoring_file=resource_monitor.get_file_path()
                if resource_monitor is not None else None,
                runtime=runtime,
                aggregator=aggregator,
                multi_threading_enabled=self.__processor.test_multithreading()
                or self.__processor.suite_multithreading())
            reporter.generate_html_report(self.__settings.html_report)
        XmlReporter.create_xml_report(write_file=self.__settings.xml_report,
                                      suites=self.get_executed_suites())
        if self.__settings.monitor_resources:
            resource_monitor.cleanup()
        return aggregator
from test_junkie.debugger import LogJunkie
from test_junkie.errors import BadParameters
from test_junkie.runner import Runner

LogJunkie.enable_logging(10)

LogJunkie.debug("1")
LogJunkie.info("2")
LogJunkie.warn("3")
LogJunkie.error("4")
LogJunkie.disable_logging()


def test_bad_runner_initiation1():
    try:
        Runner(suites=None)
        raise AssertionError(
            "Must have raised exception because bad args were passed in")
    except Exception as error:
        assert isinstance(error,
                          BadParameters), "Type of exception is incorrect"