Beispiel #1
0
 def pytest_collection_finish(
     self,
     session  # type: pytest.Session
 ):
     if xdist.is_xdist_worker(self):
         config_str = json.dumps({'noparallel_tests': self.config.noparallel_tests})
         config_item = pytest.Item.from_parent(parent=session, name='configuration item', nodeid=config_str)
         session.items[:] = [config_item] + session.items
     yield
Beispiel #2
0
        def is_xdist_master(request_or_session):
            """Return `True` if this is the xdist master, `False` otherwise

            Note: this method returns `False` when distribution has not been activated
            at all.

            :param request_or_session: the `pytest` `request` or `session` object
            :return:
            """
            return (not is_xdist_worker(request_or_session) and getattr(
                request_or_session.config.option, 'dist', 'no') != "no")
Beispiel #3
0
    def pytest_sessionstart(self, session: Session) -> None:
        import xdist

        self.is_worker = xdist.is_xdist_worker(session)
        if not self.is_worker:
            self.service.start_test_run()
        else:
            test_run = TestRun(
                zebrunner_context.settings.run.display_name,
                zebrunner_context.settings.run.environment,
                zebrunner_context.settings.run.build,
            )
            test_run.zebrunner_id = session.config.workerinput["test_run_id"]
            zebrunner_context.test_run = test_run
        inject_driver(self.session_manager)
Beispiel #4
0
def configure_logging(request, worker_id):
    """Handle xdist and ReportPortal logging configuration at session start

    Set up a separate logger for each pytest-xdist worker
    if worker_id != 'master' then xdist is running in multi-threading so
    a logfile named 'robottelo_gw{worker_id}.log' will be created.

    Add a handler for ReportPortal logging
    """
    worker_formatter = logzero.LogFormatter(
        fmt=
        f'%(asctime)s - {worker_id} - %(name)s - %(levelname)s - %(message)s',
        datefmt=DEFAULT_DATE_FORMAT,
    )
    use_rp_logger = hasattr(request.node.config, 'py_test_service')
    if use_rp_logger:
        logging.setLoggerClass(RPLogger)

    if is_xdist_worker(request):
        if f'{worker_id}' not in [h.get_name() for h in logger.handlers]:
            # Track the core logger's file handler level, set it in case core logger wasn't set
            worker_log_level = 'INFO'
            handlers_to_remove = [
                h for h in logger.handlers
                if isinstance(h, logging.FileHandler)
                and getattr(h, 'baseFilename', None) == str(robottelo_log_file)
            ]
            for handler in handlers_to_remove:
                logger.removeHandler(handler)
                worker_log_level = handler.level
            worker_handler = logging.FileHandler(
                robottelo_log_dir.joinpath(f'robottelo_{worker_id}.log'))
            worker_handler.set_name(f'{worker_id}')
            worker_handler.setFormatter(worker_formatter)
            worker_handler.setLevel(worker_log_level)
            logger.addHandler(worker_handler)

            broker_log_setup(
                'debug',
                robottelo_log_dir.joinpath(f'robottelo_{worker_id}.log'))

            if use_rp_logger:
                rp_handler = RPLogHandler(request.node.config.py_test_service)
                rp_handler.setFormatter(worker_formatter)
 def test_is_xdist_worker(self, fake_request):
     assert xdist.is_xdist_worker(fake_request)
     del fake_request.config.workerinput
     assert not xdist.is_xdist_worker(fake_request)
Beispiel #6
0
 def is_main_process(session):
     return not is_xdist_worker(session)