From 494e820042212fdc1c54d50c93e5366da61a59ce Mon Sep 17 00:00:00 2001 From: Jean-Christophe Morin Date: Mon, 14 Oct 2024 12:43:00 -0400 Subject: [PATCH] Fix empty test command when command is a list and logs are verbose Signed-off-by: Jean-Christophe Morin --- .../packages/testing_obj/1.0.0/package.py | 6 +++++ src/rez/package_test.py | 4 +++- src/rez/tests/test_test.py | 22 ++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py b/src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py index a7542b20e..162d7742a 100644 --- a/src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py +++ b/src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py @@ -22,6 +22,12 @@ def commands(): build_command = 'python {root}/build.py {install}' tests = { + "command_as_string_success": { + "command": "exit 0" + }, + "command_as_string_fail": { + "command": "exit 1" + }, "check_car_ideas": { "command": ["python", "-c", "import os; assert os.environ.get('CAR_IDEA') == 'STURDY STEERING WHEEL'"], "requires": ["python"] diff --git a/src/rez/package_test.py b/src/rez/package_test.py index b00e00f98..4c9e3d917 100644 --- a/src/rez/package_test.py +++ b/src/rez/package_test.py @@ -394,7 +394,9 @@ def run_test(self, test_name, extra_test_args=None): if isinstance(command, str): command = variant.format(command) else: - command = map(variant.format, command) + # Note that we convert the iterator to a list to + # make sure that we can consume the variable more than once. + command = [x for x in map(variant.format, command)] if extra_test_args: if isinstance(command, str): diff --git a/src/rez/tests/test_test.py b/src/rez/tests/test_test.py index 549d088f0..99bf277c8 100644 --- a/src/rez/tests/test_test.py +++ b/src/rez/tests/test_test.py @@ -34,14 +34,21 @@ def test_1(self): context = ResolvedContext(["testing_obj", "python"]) self._run_tests(context) - def _run_tests(self, r): + def test_2(self): + """package.py unit tests are correctly run in a testing environment when no verbosity is set""" + self.inject_python_repo() + context = ResolvedContext(["testing_obj", "python"]) + # This will get us more code coverage :) + self._run_tests(context, verbose=0) + + def _run_tests(self, r, verbose=2): """Run unit tests in package.py""" self.inject_python_repo() runner = PackageTestRunner( package_request="testing_obj", package_paths=r.package_paths, stop_on_fail=False, - verbose=2 + verbose=verbose ) test_names = runner.get_test_names() @@ -49,12 +56,11 @@ def _run_tests(self, r): for test_name in test_names: runner.run_test(test_name) - successful_test = self._get_test_result(runner, "check_car_ideas") - failed_test = self._get_test_result(runner, "move_meeting_to_noon") - - self.assertEqual(runner.test_results.num_tests, 2) - self.assertEqual(successful_test["status"], "success", "check_car_ideas did not succeed") - self.assertEqual(failed_test["status"], "failed", "move_meeting_to_noon did not succeed") + self.assertEqual(runner.test_results.num_tests, 4) + self.assertEqual(self._get_test_result(runner, "check_car_ideas")["status"], "success", "check_car_ideas did not succeed") + self.assertEqual(self._get_test_result(runner, "move_meeting_to_noon")["status"], "failed", "move_meeting_to_noon did not fail") + self.assertEqual(self._get_test_result(runner, "command_as_string_success")["status"], "success", "command_as_string_success did not succeed") + self.assertEqual(self._get_test_result(runner, "command_as_string_fail")["status"], "failed", "command_as_string_fail did not fail") def _get_test_result(self, runner, test_name): return next(