Skip to content

Commit 66726cf

Browse files
authored
Use pytest logging instead of runtime warnings during testing (#464)
1 parent 196ec71 commit 66726cf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ fail-on = [
326326
[tool.pytest.ini_options]
327327
addopts = "-ra --showlocals --durations=10 -p no:pytest-ansible"
328328
cache_dir = "./.cache/.pytest"
329+
log_cli = true
330+
log_cli_level = "WARNING"
329331
testpaths = "tests"
330332
tmp_path_retention_policy = "failed"
331333
verbosity_assertions = 2

tests/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from __future__ import annotations
2121

2222
import errno
23+
import logging
2324
import os
2425
import pty
2526
import re
@@ -28,7 +29,6 @@
2829
import subprocess
2930
import sys
3031
import time
31-
import warnings
3232

3333
from dataclasses import dataclass
3434
from pathlib import Path
@@ -47,6 +47,7 @@
4747

4848

4949
FIXTURES_DIR = Path(__file__).parent / "fixtures"
50+
LOGGER = logging.getLogger(__name__)
5051

5152

5253
@dataclass
@@ -301,7 +302,7 @@ def _start_container() -> None:
301302

302303
if "podman" in INFRASTRUCTURE.container_engine:
303304
cmd = BASE_CMD + PODMAN_CMD + auth_mount + END
304-
warnings.warn("Podman auth mount added: " + auth_mount, stacklevel=0)
305+
LOGGER.warning("Podman auth mount added: %s", auth_mount)
305306
elif "docker" in INFRASTRUCTURE.container_engine:
306307
cmd = BASE_CMD + DOCKER_CMD + END
307308
else:
@@ -313,7 +314,7 @@ def _start_container() -> None:
313314
container_name=INFRASTRUCTURE.container_name,
314315
image_name=INFRASTRUCTURE.image_name,
315316
)
316-
warnings.warn("Running: " + cmd, stacklevel=0)
317+
LOGGER.warning("Running: %s", cmd)
317318
try:
318319
subprocess.run(cmd, check=True, capture_output=True, shell=True, text=True)
319320
except subprocess.CalledProcessError as exc:
@@ -332,7 +333,7 @@ def _start_container() -> None:
332333
else:
333334
nav_ee = get_nav_default_ee_in_container()
334335
warning = f"localhost / . not in image name, pulling default {nav_ee} for navigator"
335-
warnings.warn(warning, stacklevel=0)
336+
LOGGER.warning(warning)
336337
INFRASTRUCTURE.navigator_ee = nav_ee
337338
_proc = _exec_container(command=f"podman pull {nav_ee}")
338339

0 commit comments

Comments
 (0)