|
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | 4 |
|
| 5 | +import logging |
| 6 | +import os |
| 7 | + |
5 | 8 | import pytest |
6 | 9 |
|
| 10 | +_LOGGER_NAME = "cuda_pathfinder.test_info" |
7 | 11 |
|
8 | | -def pytest_configure(config): |
9 | | - config.custom_info = [] |
10 | 12 |
|
| 13 | +def _info_summary_log_filename(): |
| 14 | + strictness = os.environ.get("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS", "default") |
| 15 | + return f"test-info-summary-{strictness}.log" |
11 | 16 |
|
12 | | -def pytest_terminal_summary(terminalreporter, exitstatus, config): |
13 | | - if not config.getoption("verbose"): |
14 | | - return |
15 | | - if hasattr(config.option, "iterations"): # pytest-freethreaded runs all tests at least twice |
16 | | - return |
17 | | - if getattr(config.option, "count", 1) > 1: # pytest-repeat |
18 | | - return |
19 | 17 |
|
20 | | - if config.custom_info: |
21 | | - terminalreporter.write_sep("=", "INFO summary") |
22 | | - for msg in config.custom_info: |
23 | | - terminalreporter.line(f"INFO {msg}") |
| 18 | +@pytest.fixture(scope="session") |
| 19 | +def _info_summary_handler(request): |
| 20 | + log_path = request.config.rootpath / _info_summary_log_filename() |
| 21 | + handler = logging.FileHandler(log_path, mode="w") |
| 22 | + handler.setFormatter(logging.Formatter("%(test_node)s: %(message)s")) |
24 | 23 |
|
| 24 | + logger = logging.getLogger(_LOGGER_NAME) |
| 25 | + logger.addHandler(handler) |
| 26 | + logger.setLevel(logging.DEBUG) |
| 27 | + logger.propagate = False |
25 | 28 |
|
26 | | -@pytest.fixture |
27 | | -def info_summary_append(request): |
28 | | - def _append(message): |
29 | | - request.config.custom_info.append(f"{request.node.name}: {message}") |
| 29 | + yield handler |
| 30 | + |
| 31 | + logger.removeHandler(handler) |
| 32 | + handler.close() |
30 | 33 |
|
31 | | - return _append |
| 34 | + |
| 35 | +@pytest.fixture |
| 36 | +def info_log(request, _info_summary_handler): # noqa: ARG001 |
| 37 | + return logging.LoggerAdapter( |
| 38 | + logging.getLogger(_LOGGER_NAME), |
| 39 | + extra={"test_node": request.node.name}, |
| 40 | + ) |
32 | 41 |
|
33 | 42 |
|
34 | 43 | def skip_if_missing_libnvcudla_so(libname: str, *, timeout: float) -> None: |
|
0 commit comments