diff --git a/tests/procs.py b/tests/procs.py index 668b64f..971c0e4 100644 --- a/tests/procs.py +++ b/tests/procs.py @@ -1,3 +1,4 @@ +import logging import subprocess from pathlib import Path from typing import IO, Any @@ -5,6 +6,8 @@ from typing import IO, Any _FILE = None | int | IO[Any] _DIR = None | Path | str +log = logging.getLogger(__name__) + def run( cmd: list[str], @@ -16,8 +19,8 @@ def run( env: dict[str, str] | None = None, ) -> subprocess.CompletedProcess: if cwd is not None: - print(f"cd {cwd}") - print("$ " + " ".join(cmd)) + log.debug(f"cd {cwd}") + log.debug("$ " + " ".join(cmd)) return subprocess.run( cmd, text=text, check=check, cwd=cwd, stderr=stderr, stdout=stdout, env=env ) diff --git a/tests/test_gc.py b/tests/test_gc.py index 5d80c10..8d49683 100644 --- a/tests/test_gc.py +++ b/tests/test_gc.py @@ -1,3 +1,4 @@ +import logging import subprocess import sys import unittest @@ -7,6 +8,8 @@ import pytest from .direnv_project import DirenvProject from .procs import run +log = logging.getLogger(__name__) + def common_test(direnv_project: DirenvProject) -> None: run(["nix-collect-garbage"]) @@ -54,7 +57,7 @@ def common_test_clean(direnv_project: DirenvProject) -> None: rcs = [f for f in files if f.match("*.rc")] profiles = [f for f in files if not f.match("*.rc")] if len(rcs) != 1 or len(profiles) != 1: - print(files) + log.debug(files) assert len(rcs) == 1 assert len(profiles) == 1 @@ -79,7 +82,7 @@ def test_use_flake(direnv_project: DirenvProject, strict_env: bool) -> None: # should only contain our flake-utils flake if len(inputs) != 4: run(["nix", "flake", "archive", "--json"], cwd=direnv_project.directory) - print(inputs) + log.debug(inputs) assert len(inputs) == 4 for symlink in inputs: assert symlink.is_dir() diff --git a/tests/test_use_nix.py b/tests/test_use_nix.py index af7da4e..f12cb6b 100644 --- a/tests/test_use_nix.py +++ b/tests/test_use_nix.py @@ -1,3 +1,4 @@ +import logging import os import subprocess import sys @@ -8,12 +9,14 @@ import pytest from .direnv_project import DirenvProject from .procs import run +log = logging.getLogger(__name__) + def direnv_exec( direnv_project: DirenvProject, cmd: str, env: dict[str, str] | None = None ) -> None: args = ["direnv", "exec", str(direnv_project.directory), "sh", "-c", cmd] - print("$ " + " ".join(args)) + log.debug("$ " + " ".join(args)) out = run( args, stderr=subprocess.PIPE,