Skip to content

Commit 7f15da2

Browse files
committed
Use obtain_file to get file for test_cases_step
Searching only `source_paths` is inconsistent with how patches etc. are located making it impossible to place tests e.g. next to easyconfigs or in software-specific source folders.
1 parent d38174b commit 7f15da2

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

easybuild/framework/easyblock.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4707,14 +4707,9 @@ def test_cases_step(self):
47074707
if os.path.isabs(test):
47084708
test_cmd = test
47094709
else:
4710-
for source_path in source_paths():
4711-
test_cmd = os.path.join(source_path, self.name, test)
4712-
if os.path.exists(test_cmd):
4713-
break
4714-
else:
4715-
test_cmd = test
4710+
test_cmd = self.obtain_file(test, no_download=True, warning_only=True) or test
47164711
if not os.path.exists(test_cmd):
4717-
raise EasyBuildError(f"Test specifies non-existing path: {test_cmd}")
4712+
raise EasyBuildError(f"Test specifies non-existing path: {test}")
47184713

47194714
if os.path.isfile(test_cmd):
47204715
original_perms = os.lstat(test_cmd).st_mode
@@ -4724,8 +4719,8 @@ def test_cases_step(self):
47244719
adjust_permissions(test_cmd, stat.S_IEXEC, add=True, recursive=False)
47254720
else:
47264721
original_perms = None
4722+
self.log.debug(f"Running test {test_cmd}")
47274723
try:
4728-
self.log.debug(f"Running test {test_cmd}")
47294724
run_shell_cmd(test_cmd)
47304725
except RunShellCmdError:
47314726
raise # Let that propagate which will report more information

test/framework/easyblock.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,21 @@ def test_test_cases_step(self):
13381338
self.assertIn('Test case success', log_txt)
13391339
self.assertIn('Test case failure', log_txt)
13401340

1341+
# Test is found when put next to easyconfig file, and preferred
1342+
new_mock_test_bin = os.path.join(os.path.dirname(self.eb_file), os.path.basename(mock_test_bin))
1343+
write_file(new_mock_test_bin, '#!/bin/bash\necho "new test passed"')
1344+
new_mock_test_bin2 = os.path.join(os.path.dirname(self.eb_file), 'example_test2')
1345+
write_file(new_mock_test_bin2, '#!/bin/bash\necho "additional test passed"')
1346+
eb.cfg['tests'] = [os.path.basename(new_mock_test_bin), os.path.basename(new_mock_test_bin2)]
1347+
1348+
write_file(eb.logfile, '') # reset log file
1349+
eb.test_cases_step()
1350+
logtxt = read_file(eb.logfile)
1351+
self.assertIn(f'Running test {new_mock_test_bin}', logtxt)
1352+
self.assertIn(f'Running test {new_mock_test_bin2}', logtxt)
1353+
self.assertIn("new test passed", logtxt)
1354+
self.assertIn("additional test passed", logtxt)
1355+
13411356
def test_post_processing_step(self):
13421357
"""Test post_processing_step and deprecated post_install_step."""
13431358
init_config(build_options={'silent': True})

0 commit comments

Comments
 (0)