From 57ce1c69e0f9227d3e7bdb39ab2d7d3db31babad Mon Sep 17 00:00:00 2001 From: Hank Wikle Date: Thu, 21 Nov 2024 15:27:20 -0700 Subject: [PATCH] Fix unit test for status command before running tests This commit fixes an issue in which a recently committed regression test passes even when it shouldn't. The test should now fail if the regression is reintroduced. --- test/tests/status_cmd_tests.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/tests/status_cmd_tests.py b/test/tests/status_cmd_tests.py index 792f571b4..ddf93e01b 100644 --- a/test/tests/status_cmd_tests.py +++ b/test/tests/status_cmd_tests.py @@ -301,12 +301,20 @@ def test_status_history(self): def test_status_no_run(self): """Test that the status command behaves properly when invoked before any tests have run.""" + # Create a temporary empty working directory to simulate a fresh install + self.pav_cfg.working_dir = self.pav_cfg.working_dir / "working_dir" + self.pav_cfg.working_dir.mkdir() + status_cmd = commands.get_command('status') - out = io.StringIO() - status_cmd.outfile = out + status_cmd.silence() parser = argparse.ArgumentParser() status_cmd._setup_arguments(parser) args = parser.parse_args([]) - self.assertEqual(status_cmd.run(self.pav_cfg, args), 0) + ret = status_cmd.run(self.pav_cfg, args) + + # Reset working directory for other tests + self.pav_cfg.working_dir = self.pav_cfg.working_dir.parent + + self.assertEqual(ret, 0)