Skip to content

Commit b71c84d

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 2c41dc8 commit b71c84d

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

easybuild/framework/easyblock.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4700,17 +4700,11 @@ def test_cases_step(self):
47004700
if os.path.isabs(test):
47014701
test_cmd = test
47024702
else:
4703-
for source_path in source_paths():
4704-
test_cmd = os.path.join(source_path, self.name, test)
4705-
if os.path.exists(test_cmd):
4706-
break
4707-
else:
4708-
test_cmd = test # Reset at and of loop
4709-
if not os.path.exists(test_cmd):
4710-
raise EasyBuildError(f"Test specifies non-existing path: {test_cmd}")
4703+
test_cmd = self.obtain_file(test, no_download=True, warning_only=True) or test
4704+
if not os.path.exists(test_cmd):
4705+
raise EasyBuildError(f"Test specifies non-existing path: {test}")
47114706

47124707
try:
4713-
self.log.debug(f"Running test {test_cmd}")
47144708
run_shell_cmd(test_cmd)
47154709
except EasyBuildError as err:
47164710
raise EasyBuildError(f"Running test {test_cmd} failed: {err}")

test/framework/easyblock.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,23 @@ def test_test_cases_step(self):
13441344
eb.test_cases_step()
13451345
self.assertIn("test passed", read_file(eb.logfile))
13461346

1347+
# Test is found when put next to easyconfig file, and preferred
1348+
test_file = os.path.join(os.path.dirname(self.eb_file), os.path.basename(test_file))
1349+
write_file(test_file, '#!/bin/bash\necho "new test passed"')
1350+
test_file2 = os.path.join(os.path.dirname(self.eb_file), 'example_test2')
1351+
write_file(test_file2, '#!/bin/bash\necho "additional test passed"')
1352+
adjust_permissions(test_file, stat.S_IXUSR, add=True)
1353+
adjust_permissions(test_file2, stat.S_IXUSR, add=True)
1354+
self.contents += "\ntests = ['example_test', 'example_test2']"
1355+
self.writeEC()
1356+
eb = EasyBlock(EasyConfig(self.eb_file))
1357+
1358+
write_file(eb.logfile, '') # reset log file
1359+
eb.test_cases_step()
1360+
logtxt = read_file(eb.logfile)
1361+
self.assertIn("new test passed", logtxt)
1362+
self.assertIn("additional test passed", logtxt)
1363+
13471364
def test_extensions_step(self):
13481365
"""Test the extensions_step"""
13491366
init_config(build_options={'silent': True})

0 commit comments

Comments
 (0)