Skip to content

Commit 494e820

Browse files
Fix empty test command when command is a list and logs are verbose
Signed-off-by: Jean-Christophe Morin <[email protected]>
1 parent 4aa98e8 commit 494e820

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/rez/data/tests/builds/packages/testing_obj/1.0.0/package.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def commands():
2222
build_command = 'python {root}/build.py {install}'
2323

2424
tests = {
25+
"command_as_string_success": {
26+
"command": "exit 0"
27+
},
28+
"command_as_string_fail": {
29+
"command": "exit 1"
30+
},
2531
"check_car_ideas": {
2632
"command": ["python", "-c", "import os; assert os.environ.get('CAR_IDEA') == 'STURDY STEERING WHEEL'"],
2733
"requires": ["python"]

src/rez/package_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ def run_test(self, test_name, extra_test_args=None):
394394
if isinstance(command, str):
395395
command = variant.format(command)
396396
else:
397-
command = map(variant.format, command)
397+
# Note that we convert the iterator to a list to
398+
# make sure that we can consume the variable more than once.
399+
command = [x for x in map(variant.format, command)]
398400

399401
if extra_test_args:
400402
if isinstance(command, str):

src/rez/tests/test_test.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,33 @@ def test_1(self):
3434
context = ResolvedContext(["testing_obj", "python"])
3535
self._run_tests(context)
3636

37-
def _run_tests(self, r):
37+
def test_2(self):
38+
"""package.py unit tests are correctly run in a testing environment when no verbosity is set"""
39+
self.inject_python_repo()
40+
context = ResolvedContext(["testing_obj", "python"])
41+
# This will get us more code coverage :)
42+
self._run_tests(context, verbose=0)
43+
44+
def _run_tests(self, r, verbose=2):
3845
"""Run unit tests in package.py"""
3946
self.inject_python_repo()
4047
runner = PackageTestRunner(
4148
package_request="testing_obj",
4249
package_paths=r.package_paths,
4350
stop_on_fail=False,
44-
verbose=2
51+
verbose=verbose
4552
)
4653

4754
test_names = runner.get_test_names()
4855

4956
for test_name in test_names:
5057
runner.run_test(test_name)
5158

52-
successful_test = self._get_test_result(runner, "check_car_ideas")
53-
failed_test = self._get_test_result(runner, "move_meeting_to_noon")
54-
55-
self.assertEqual(runner.test_results.num_tests, 2)
56-
self.assertEqual(successful_test["status"], "success", "check_car_ideas did not succeed")
57-
self.assertEqual(failed_test["status"], "failed", "move_meeting_to_noon did not succeed")
59+
self.assertEqual(runner.test_results.num_tests, 4)
60+
self.assertEqual(self._get_test_result(runner, "check_car_ideas")["status"], "success", "check_car_ideas did not succeed")
61+
self.assertEqual(self._get_test_result(runner, "move_meeting_to_noon")["status"], "failed", "move_meeting_to_noon did not fail")
62+
self.assertEqual(self._get_test_result(runner, "command_as_string_success")["status"], "success", "command_as_string_success did not succeed")
63+
self.assertEqual(self._get_test_result(runner, "command_as_string_fail")["status"], "failed", "command_as_string_fail did not fail")
5864

5965
def _get_test_result(self, runner, test_name):
6066
return next(

0 commit comments

Comments
 (0)