diff --git a/test/functional/conftest.py b/test/functional/conftest.py index bce73895..48e89e3d 100644 --- a/test/functional/conftest.py +++ b/test/functional/conftest.py @@ -51,12 +51,14 @@ def redfish_conn_mock(): def run_cli_command(): """Fixture that returns a function to run CLI commands.""" - def _run_command(args: List[str], check: bool = False): + def _run_command(args: List[str], check: bool = False, cwd=None): """Run a node-scraper CLI command. Args: args: List of command-line arguments check: If True, raise CalledProcessError on non-zero exit + cwd: Working directory for the command (default: the caller's). Use a tmp dir for + plugins whose probes write files to the cwd, e.g. wget saving index.html Returns: subprocess.CompletedProcess instance @@ -68,6 +70,7 @@ def _run_command(args: List[str], check: bool = False): capture_output=True, text=True, check=check, + cwd=cwd, ) return _run_command diff --git a/test/functional/test_cli_no_console_log.py b/test/functional/test_cli_no_console_log.py index ed9fd8fa..7021ac90 100644 --- a/test/functional/test_cli_no_console_log.py +++ b/test/functional/test_cli_no_console_log.py @@ -28,7 +28,7 @@ import sys -def test_no_console_log_with_log_path_none_still_parses(): +def test_no_console_log_with_log_path_none_still_parses(tmp_path): """--log-path None + --no-console-log defaults to ./scraper_logs_* (no argparse error).""" result = subprocess.run( [ @@ -44,6 +44,7 @@ def test_no_console_log_with_log_path_none_still_parses(): ], capture_output=True, text=True, + cwd=tmp_path, ) assert result.returncode == 0, result.stderr combined = (result.stdout or "") + (result.stderr or "") diff --git a/test/functional/test_network_plugin.py b/test/functional/test_network_plugin.py index d4ff71fc..e34cbfb8 100644 --- a/test/functional/test_network_plugin.py +++ b/test/functional/test_network_plugin.py @@ -158,6 +158,7 @@ def test_network_plugin_with_netprobe_wget(run_cli_command, tmp_path): "wget", ], check=False, + cwd=tmp_path, # wget saves the fetched page (index.html, index.html.1, ...) into the cwd ) assert result.returncode in [0, 1, 2] diff --git a/test/functional/test_plugin_configs.py b/test/functional/test_plugin_configs.py index e1cf358f..05cebda1 100644 --- a/test/functional/test_plugin_configs.py +++ b/test/functional/test_plugin_configs.py @@ -181,25 +181,34 @@ def test_plugin_config_with_multiple_configs(run_cli_command, plugin_config_file def test_plugin_config_with_nonexistent_file(run_cli_command, tmp_path): """Test that a nonexistent config file path fails gracefully.""" nonexistent_path = str(tmp_path / "nonexistent_config.json") - result = run_cli_command([f"--plugin-configs={nonexistent_path}"], check=False) + result = run_cli_command( + ["--log-path", str(tmp_path / "logs"), f"--plugin-configs={nonexistent_path}"], + check=False, + ) assert result.returncode != 0 output = (result.stdout + result.stderr).lower() assert "error" in output or "no plugin config found" in output -def test_plugin_config_with_invalid_builtin_name(run_cli_command): +def test_plugin_config_with_invalid_builtin_name(run_cli_command, tmp_path): """Test that an invalid built-in config name fails gracefully.""" - result = run_cli_command(["--plugin-configs=NonExistentConfig"], check=False) + result = run_cli_command( + ["--log-path", str(tmp_path / "logs"), "--plugin-configs=NonExistentConfig"], + check=False, + ) assert result.returncode != 0 output = (result.stdout + result.stderr).lower() assert "error" in output or "no plugin config found" in output -def test_plugin_config_with_invalid_json(run_cli_command, invalid_plugin_config): +def test_plugin_config_with_invalid_json(run_cli_command, invalid_plugin_config, tmp_path): """Test that an invalid JSON file fails gracefully.""" - result = run_cli_command([f"--plugin-configs={invalid_plugin_config}"], check=False) + result = run_cli_command( + ["--log-path", str(tmp_path / "logs"), f"--plugin-configs={invalid_plugin_config}"], + check=False, + ) assert result.returncode != 0 output = (result.stdout + result.stderr).lower() diff --git a/test/functional/test_run_plugins.py b/test/functional/test_run_plugins.py index 1844d427..98e9738c 100644 --- a/test/functional/test_run_plugins.py +++ b/test/functional/test_run_plugins.py @@ -93,9 +93,12 @@ def test_run_all_plugins_together(run_cli_command, all_plugins, tmp_path): assert len(output) > 0 -def test_run_plugin_with_invalid_name(run_cli_command): +def test_run_plugin_with_invalid_name(run_cli_command, tmp_path): """Test that running a non-existent plugin logs a warning and falls back to default config.""" - result = run_cli_command(["run-plugins", "NonExistentPlugin"], check=False) + result = run_cli_command( + ["--log-path", str(tmp_path / "logs"), "run-plugins", "NonExistentPlugin"], + check=False, + ) # Invalid plugin is ignored and default config runs instead # Exit code depends on whether default config plugins succeed diff --git a/test/unit/framework/test_compare_runs.py b/test/unit/framework/test_compare_runs.py index b9fad638..cfa59531 100644 --- a/test/unit/framework/test_compare_runs.py +++ b/test/unit/framework/test_compare_runs.py @@ -126,24 +126,30 @@ def test_run_compare_runs_no_data(caplog, tmp_path): (tmp_path / "run2").mkdir() logger = logging.getLogger() plugin_reg = PluginRegistry() - run_compare_runs(str(tmp_path / "run1"), str(tmp_path / "run2"), plugin_reg, logger) + run_compare_runs( + str(tmp_path / "run1"), + str(tmp_path / "run2"), + plugin_reg, + logger, + artifact_dir=str(tmp_path), + ) assert "No plugin data found" in caplog.text -def test_run_compare_runs_with_fixture_dirs(caplog, framework_fixtures_path): +def test_run_compare_runs_with_fixture_dirs(caplog, framework_fixtures_path, tmp_path): """With two log dirs using fixture (same content), table is produced and no diffs.""" caplog.set_level(logging.INFO) logger = logging.getLogger() plugin_reg = PluginRegistry() base = framework_fixtures_path / "log_dir" - run_compare_runs(str(base), str(base), plugin_reg, logger) + run_compare_runs(str(base), str(base), plugin_reg, logger, artifact_dir=str(tmp_path)) assert "Loading run 1" in caplog.text assert "Loading run 2" in caplog.text assert "Plugin" in caplog.text assert "No differences" in caplog.text or "difference" in caplog.text.lower() -def test_run_compare_runs_sysctl_fixture(caplog, framework_fixtures_path): +def test_run_compare_runs_sysctl_fixture(caplog, framework_fixtures_path, tmp_path): """Compare runs using compare_runs_sysctl fixtures; run1 and run2 differ (SysctlPlugin).""" caplog.set_level(logging.INFO) logger = logging.getLogger() @@ -151,7 +157,7 @@ def test_run_compare_runs_sysctl_fixture(caplog, framework_fixtures_path): run1 = base / "run1" run2 = base / "run2" plugin_reg = PluginRegistry() - run_compare_runs(str(run1), str(run2), plugin_reg, logger) + run_compare_runs(str(run1), str(run2), plugin_reg, logger, artifact_dir=str(tmp_path)) assert "Loading run 1" in caplog.text assert "Loading run 2" in caplog.text assert "Sysctl" in caplog.text or "sysctl" in caplog.text @@ -167,7 +173,7 @@ def test_run_compare_runs_one_run_missing_plugin(caplog, framework_fixtures_path run2 = tmp_path / "run2" run2.mkdir() # run2 has no collector dirs - run_compare_runs(str(run1), str(run2), plugin_reg, logger) + run_compare_runs(str(run1), str(run2), plugin_reg, logger, artifact_dir=str(tmp_path)) assert "Loading run 1" in caplog.text assert "Loading run 2" in caplog.text assert "not found in run 2" in caplog.text or "NOT_RAN" in caplog.text