Skip to content

Commit

Permalink
Fix empty test command when command is a list and logs are verbose
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Oct 14, 2024
1 parent 4aa98e8 commit 494e820
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 3 additions & 1 deletion src/rez/package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 14 additions & 8 deletions src/rez/tests/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,33 @@ 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()

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(
Expand Down

0 comments on commit 494e820

Please sign in to comment.