Stand-alone tests: distinguish NO-TESTS from PASSED (#25880)
Co-authored-by: Seth R. Johnson <johnsonsr@ornl.gov>
This commit is contained in:
parent
675bdada49
commit
5a9e5ddb3d
@ -135,10 +135,15 @@ def __call__(self, *args, **kwargs):
|
|||||||
dirty=dirty
|
dirty=dirty
|
||||||
)
|
)
|
||||||
|
|
||||||
# Clean up on success and log passed test
|
# Clean up on success
|
||||||
if remove_directory:
|
if remove_directory:
|
||||||
shutil.rmtree(test_dir)
|
shutil.rmtree(test_dir)
|
||||||
self.write_test_result(spec, 'PASSED')
|
|
||||||
|
# Log test status based on whether any non-pass-only test
|
||||||
|
# functions were called
|
||||||
|
tested = os.path.exists(self.tested_file_for_spec(spec))
|
||||||
|
status = 'PASSED' if tested else 'NO-TESTS'
|
||||||
|
self.write_test_result(spec, status)
|
||||||
except BaseException as exc:
|
except BaseException as exc:
|
||||||
self.fails += 1
|
self.fails += 1
|
||||||
if isinstance(exc, (SyntaxError, TestSuiteSpecError)):
|
if isinstance(exc, (SyntaxError, TestSuiteSpecError)):
|
||||||
@ -194,6 +199,13 @@ def log_file_for_spec(self, spec):
|
|||||||
def test_dir_for_spec(self, spec):
|
def test_dir_for_spec(self, spec):
|
||||||
return self.stage.join(self.test_pkg_id(spec))
|
return self.stage.join(self.test_pkg_id(spec))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tested_file_name(cls, spec):
|
||||||
|
return '%s-tested.txt' % cls.test_pkg_id(spec)
|
||||||
|
|
||||||
|
def tested_file_for_spec(self, spec):
|
||||||
|
return self.stage.join(self.tested_file_name(spec))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_test_cache_dir(self):
|
def current_test_cache_dir(self):
|
||||||
if not (self.current_test_spec and self.current_base_spec):
|
if not (self.current_test_spec and self.current_base_spec):
|
||||||
|
@ -1785,12 +1785,14 @@ def do_test(self, dirty=False):
|
|||||||
# Clear test failures
|
# Clear test failures
|
||||||
self.test_failures = []
|
self.test_failures = []
|
||||||
self.test_log_file = self.test_suite.log_file_for_spec(self.spec)
|
self.test_log_file = self.test_suite.log_file_for_spec(self.spec)
|
||||||
|
self.tested_file = self.test_suite.tested_file_for_spec(self.spec)
|
||||||
fsys.touch(self.test_log_file) # Otherwise log_parse complains
|
fsys.touch(self.test_log_file) # Otherwise log_parse complains
|
||||||
|
|
||||||
kwargs = {'dirty': dirty, 'fake': False, 'context': 'test'}
|
kwargs = {'dirty': dirty, 'fake': False, 'context': 'test'}
|
||||||
spack.build_environment.start_build_process(self, test_process, kwargs)
|
spack.build_environment.start_build_process(self, test_process, kwargs)
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
|
# Defer tests to virtual and concrete packages
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_test(self, exe, options=[], expected=[], status=0,
|
def run_test(self, exe, options=[], expected=[], status=0,
|
||||||
@ -2605,6 +2607,7 @@ def test_process(pkg, kwargs):
|
|||||||
test_specs = [pkg.spec] + [spack.spec.Spec(v_name)
|
test_specs = [pkg.spec] + [spack.spec.Spec(v_name)
|
||||||
for v_name in sorted(v_names)]
|
for v_name in sorted(v_names)]
|
||||||
|
|
||||||
|
ran_actual_test_function = False
|
||||||
try:
|
try:
|
||||||
with fsys.working_dir(
|
with fsys.working_dir(
|
||||||
pkg.test_suite.test_dir_for_spec(pkg.spec)):
|
pkg.test_suite.test_dir_for_spec(pkg.spec)):
|
||||||
@ -2639,7 +2642,16 @@ def test_process(pkg, kwargs):
|
|||||||
if not isinstance(test_fn, types.FunctionType):
|
if not isinstance(test_fn, types.FunctionType):
|
||||||
test_fn = test_fn.__func__
|
test_fn = test_fn.__func__
|
||||||
|
|
||||||
|
# Skip any test methods consisting solely of 'pass'
|
||||||
|
# since they do not contribute to package testing.
|
||||||
|
source = (inspect.getsource(test_fn)).splitlines()[1:]
|
||||||
|
lines = (ln.strip() for ln in source)
|
||||||
|
statements = [ln for ln in lines if not ln.startswith('#')]
|
||||||
|
if len(statements) > 0 and statements[0] == 'pass':
|
||||||
|
continue
|
||||||
|
|
||||||
# Run the tests
|
# Run the tests
|
||||||
|
ran_actual_test_function = True
|
||||||
test_fn(pkg)
|
test_fn(pkg)
|
||||||
|
|
||||||
# If fail-fast was on, we error out above
|
# If fail-fast was on, we error out above
|
||||||
@ -2651,6 +2663,11 @@ def test_process(pkg, kwargs):
|
|||||||
# reset debug level
|
# reset debug level
|
||||||
tty.set_debug(old_debug)
|
tty.set_debug(old_debug)
|
||||||
|
|
||||||
|
# flag the package as having been tested (i.e., ran one or more
|
||||||
|
# non-pass-only methods
|
||||||
|
if ran_actual_test_function:
|
||||||
|
fsys.touch(pkg.tested_file)
|
||||||
|
|
||||||
|
|
||||||
inject_flags = PackageBase.inject_flags
|
inject_flags = PackageBase.inject_flags
|
||||||
env_flags = PackageBase.env_flags
|
env_flags = PackageBase.env_flags
|
||||||
|
Loading…
Reference in New Issue
Block a user