mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-22 07:42:16 +00:00
test/pylib: make pytest logging config robust when ini is missing
Make pytest logging config robust when the ini is missing and prevents crashing Pytest on the configuration stage in case the wrong tests path is provided. Fixes: SCYLLADB-1998 Closes scylladb/scylladb#29941
This commit is contained in:
committed by
Botond Dénes
parent
4c2ce1928c
commit
ff51e9c620
@@ -386,6 +386,8 @@ def pytest_sessionfinish(session: pytest.Session) -> None:
|
||||
def pytest_configure(config: pytest.Config) -> None:
|
||||
global _pytest_config
|
||||
_pytest_config = config
|
||||
log_file_format = config.getini("log_file_format") or config.getini("log_format") or "%(asctime)s %(levelname)s %(name)s> %(message)s"
|
||||
log_file_level = config.getini("log_file_level") or config.getini("log_level") or "INFO"
|
||||
|
||||
pytest_log_dir = pathlib.Path(_pytest_config.getoption("--tmpdir")).absolute() / PYTEST_LOG_FOLDER
|
||||
worker_id = os.environ.get("PYTEST_XDIST_WORKER")
|
||||
@@ -413,10 +415,11 @@ def pytest_configure(config: pytest.Config) -> None:
|
||||
for handler in root_logger.handlers[:]:
|
||||
root_logger.removeHandler(handler)
|
||||
handler.close()
|
||||
|
||||
file_handler = logging.FileHandler(_pytest_config.stash[PYTEST_LOG_FILE])
|
||||
file_handler.setFormatter(logging.Formatter(config.getini("log_file_format")))
|
||||
file_handler.setFormatter(logging.Formatter(log_file_format))
|
||||
root_logger.addHandler(file_handler)
|
||||
root_logger.setLevel(config.getini("log_file_level"))
|
||||
root_logger.setLevel(log_file_level)
|
||||
|
||||
if config.getoption("--exe-url") and config.getoption("--exe-path"):
|
||||
raise RuntimeError("Can't use --exe-url and exe-path simultaneously.")
|
||||
|
||||
Reference in New Issue
Block a user