Skip to content

Commit

Permalink
Use pytest logging instead of runtime warnings during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Nov 4, 2024
1 parent 196ec71 commit d9688bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ fail-on = [
[tool.pytest.ini_options]
addopts = "-ra --showlocals --durations=10 -p no:pytest-ansible"
cache_dir = "./.cache/.pytest"
log_cli = true
log_cli_level = "WARNING"
testpaths = "tests"
tmp_path_retention_policy = "failed"
verbosity_assertions = 2
Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from __future__ import annotations

import errno
import logging
import os
import pty
import re
Expand All @@ -28,7 +29,6 @@
import subprocess
import sys
import time
import warnings

from dataclasses import dataclass
from pathlib import Path
Expand All @@ -47,6 +47,7 @@


FIXTURES_DIR = Path(__file__).parent / "fixtures"
LOGGER = logging.getLogger(__name__)


@dataclass
Expand Down Expand Up @@ -301,7 +302,7 @@ def _start_container() -> None:

if "podman" in INFRASTRUCTURE.container_engine:
cmd = BASE_CMD + PODMAN_CMD + auth_mount + END
warnings.warn("Podman auth mount added: " + auth_mount, stacklevel=0)
LOGGER.warning("Podman auth mount added: %s", auth_mount)
elif "docker" in INFRASTRUCTURE.container_engine:
cmd = BASE_CMD + DOCKER_CMD + END
else:
Expand All @@ -313,7 +314,7 @@ def _start_container() -> None:
container_name=INFRASTRUCTURE.container_name,
image_name=INFRASTRUCTURE.image_name,
)
warnings.warn("Running: " + cmd, stacklevel=0)
LOGGER.warning("Running: %s", cmd)
try:
subprocess.run(cmd, check=True, capture_output=True, shell=True, text=True)
except subprocess.CalledProcessError as exc:
Expand All @@ -332,7 +333,7 @@ def _start_container() -> None:
else:
nav_ee = get_nav_default_ee_in_container()
warning = f"localhost / . not in image name, pulling default {nav_ee} for navigator"
warnings.warn(warning, stacklevel=0)
LOGGER.warning(warning)
INFRASTRUCTURE.navigator_ee = nav_ee
_proc = _exec_container(command=f"podman pull {nav_ee}")

Expand Down

0 comments on commit d9688bb

Please sign in to comment.