From e2430109f7cd99320cbe05e35bb321602d7f2e5e Mon Sep 17 00:00:00 2001 From: Mike Shriver Date: Fri, 19 Feb 2021 10:06:12 -0500 Subject: [PATCH] Fix xdist worker logging Default --show-capture to no nailgun/airgun client logging getting dumped to the console is obtrusive, creating consoles scores of megabytes in size when the entire test suite is run. --- pyproject.toml | 1 + tests/foreman/conftest.py | 24 +++++------------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 863708aa574..b81e6996215 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,3 +18,4 @@ exclude = ''' [tool.pytest.ini_options] junit_logging = 'all' +addopts = '--show-capture=no' diff --git a/tests/foreman/conftest.py b/tests/foreman/conftest.py index 3a71aeb7c0a..71b677d3bf6 100644 --- a/tests/foreman/conftest.py +++ b/tests/foreman/conftest.py @@ -53,16 +53,6 @@ def pytest_report_header(config): return messages -@pytest.fixture(scope="session") -def worker_id(request): - """Gets the worker ID when running in multi-threading with xdist""" - if hasattr(request.config, 'slaveinput'): - # return gw+(0..n) - return request.config.slaveinput['slaveid'] - else: - return 'master' - - @pytest.fixture(scope="session") def configured_settings(): if not settings.configured: @@ -70,18 +60,17 @@ def configured_settings(): return settings -@pytest.fixture(autouse=True, scope='module') +@pytest.fixture(autouse=True, scope='session') def robottelo_logger(request, worker_id): """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. """ logger = logging.getLogger('robottelo') - if ( - hasattr(request.session.config, '_reportportal_configured') - and request.session.config._reportportal_configured - ): + use_rp_logger = getattr(request.session.config, '_reportportal_configured', False) + if use_rp_logger: logging.setLoggerClass(RPLogger) + if f'{worker_id}' not in [h.get_name() for h in logger.handlers]: if worker_id != 'master': formatter = logging.Formatter( @@ -95,10 +84,7 @@ def robottelo_logger(request, worker_id): logger.addHandler(handler) # Nailgun HTTP logs should also be included in gw* logs logging.getLogger('nailgun').addHandler(handler) - if ( - hasattr(request.session.config, '_reportportal_configured') - and request.session.config._reportportal_configured - ): + if use_rp_logger: rp_handler = RPLogHandler(request.node.config.py_test_service) rp_handler.set_name(f'{worker_id}') rp_handler.setFormatter(formatter)