diff --git a/tests/project_helpers.py b/tests/project_helpers.py index 38b445b8..c05445a4 100644 --- a/tests/project_helpers.py +++ b/tests/project_helpers.py @@ -1,6 +1,7 @@ """Common helpers shared between test_real_project and test_sample_projects.""" import hashlib import logging +import os import shlex import subprocess import sys @@ -150,7 +151,7 @@ def venv_hash(self) -> str: The Python version currently used to run the tests is used to compute the hash and create the venv. """ - dummy_script = self.venv_script_lines(Path("/dev/null")) + dummy_script = self.venv_script_lines(Path(os.devnull)) py_version = f"{sys.version_info.major},{sys.version_info.minor}" script_and_version_bytes = ("".join(dummy_script) + py_version).encode() return hashlib.sha256(script_and_version_bytes).hexdigest() diff --git a/tests/test_cmdline_options.py b/tests/test_cmdline_options.py index f0b58d01..2cd02d3d 100644 --- a/tests/test_cmdline_options.py +++ b/tests/test_cmdline_options.py @@ -192,7 +192,7 @@ def test_options_interactions__correct_options__does_not_abort(cli_arguments): ) args = basepath + drawn_args - with open("/dev/null", "w") as f_out: + with open(os.devnull, "w") as f_out: exit_code = main(cmdline_args=args, stdin=io.StringIO(to_stdin), stdout=f_out) assert exit_code in {0, 3, 4} diff --git a/tests/test_real_projects.py b/tests/test_real_projects.py index 0eafb8ee..f782f3da 100644 --- a/tests/test_real_projects.py +++ b/tests/test_real_projects.py @@ -7,7 +7,9 @@ """ import json import logging +import os import subprocess +import sys import tarfile from dataclasses import dataclass from pathlib import Path @@ -51,7 +53,7 @@ def verify_requirements(venv_path: Path, requirements: List[str]) -> None: def run_fawltydeps_json( *args: str, venv_dir: Optional[Path], cwd: Optional[Path] = None ) -> JsonData: - argv = ["fawltydeps", "--config-file=/dev/null", "--json"] + argv = [sys.executable, "-m", "fawltydeps", f"--config-file={os.devnull}", "--json"] if venv_dir is not None: argv += [f"--pyenv={venv_dir}"] proc = subprocess.run( diff --git a/tests/utils.py b/tests/utils.py index 90452de4..f3d40e45 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -4,6 +4,7 @@ import logging import os import subprocess +import sys from dataclasses import dataclass, field, replace from pathlib import Path from pprint import pformat @@ -106,13 +107,14 @@ def unused_factory(*deps: str) -> List[UnusedDependency]: def run_fawltydeps_subprocess( *args: str, - config_file: Path = Path("/dev/null"), + config_file: Path = Path(os.devnull), to_stdin: Optional[str] = None, cwd: Optional[Path] = None, ) -> Tuple[str, str, int]: """Run FawltyDeps as a subprocess. Designed for integration tests.""" proc = subprocess.run( - ["fawltydeps", f"--config-file={config_file}"] + list(args), + [sys.executable, "-m", "fawltydeps", f"--config-file={config_file}"] + + list(args), input=to_stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -131,7 +133,7 @@ def run_fawltydeps_subprocess( def run_fawltydeps_function( *args: str, - config_file: Path = Path("/dev/null"), + config_file: Path = Path(os.devnull), to_stdin: Optional[Union[str, bytes]] = None, basepath: Optional[Path] = None, ) -> Tuple[str, int]: