in selftest/conftest.py [0:0]
def pytest_configure(config):
"""Configure pytest logging and artifacts directory.
Create artifacts directory based on the current timestamp if not configured.
This is used to store logs and other artifacts generated during the test run.
If running under pytest-xdist, use the worker ID to create separate logs for each worker.
"""
artifacts_path = os.getenv("SELFTEST_ARTIFACTS_PATH")
if "PYTEST_XDIST_WORKER" not in os.environ:
if not artifacts_path:
timestamp = datetime.now().strftime("%Y%m%d%H%M%S%f")
artifacts_path = f"/tmp/selftest-{timestamp}"
os.environ["SELFTEST_ARTIFACTS_PATH"] = artifacts_path
print(f"artifacts={artifacts_path}", file=sys.stderr)
artifacts_path = os.getenv("SELFTEST_ARTIFACTS_PATH")
assert artifacts_path, "SELFTEST_ARTIFACTS_PATH must be set"
log_path = Path(artifacts_path)
log_path.mkdir(parents=True, exist_ok=True)
worker_id = os.environ.get("PYTEST_XDIST_WORKER")
if worker_id is not None:
logging.basicConfig(
format="%(asctime)s [%(levelname)s] %(message)s",
filename=log_path / f"{worker_id}.log",
level=logging.DEBUG,
)
else:
logging.basicConfig(
format="%(asctime)s [%(levelname)s] %(message)s",
filename=log_path / "main.log",
level=logging.DEBUG,
)
logger.debug("test")