Skip to content

Commit db2ed46

Browse files
committed
Print test description with detailed listing
Signed-off-by: Jack Morrison <[email protected]>
1 parent b57f957 commit db2ed46

File tree

4 files changed

+116
-3
lines changed

4 files changed

+116
-3
lines changed

examples/tutorial/stream/stream_runonly.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class stream_test(rfm.RunOnlyRegressionTest):
1111
valid_systems = ['*']
1212
valid_prog_environs = ['*']
1313
executable = 'stream.x'
14+
descr = 'Run the STREAM memory bandwidth benchmark.'
1415

1516
@sanity_function
1617
def validate(self):

reframe/frontend/cli.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ def dep_lines(u, *, prefix, depth=0, lines=None, printed=None,
9797

9898
location = inspect.getfile(type(u.check))
9999
if detailed:
100-
details = (f' [variant: {u.check.variant_num}, '
101-
f'file: {location!r}]')
100+
details_fields = [
101+
f'variant: {u.check.variant_num}',
102+
f'file: {location!r}'
103+
]
104+
if hasattr(u.check, 'descr') and u.check.descr:
105+
details_fields.append(f'description: {u.check.descr}')
106+
details = '\n' + '\n'.join(f'{prefix} {field}' for field in details_fields)
102107

103108
lines.append(f'{prefix}^{name_info}{tc_info}{details}')
104109

@@ -115,7 +120,13 @@ def dep_lines(u, *, prefix, depth=0, lines=None, printed=None,
115120

116121
location = inspect.getfile(type(t.check))
117122
if detailed:
118-
details = f' [variant: {t.check.variant_num}, file: {location!r}]'
123+
details_fields = [
124+
f'variant: {t.check.variant_num}',
125+
f'file: {location!r}'
126+
]
127+
if hasattr(t.check, 'descr') and t.check.descr:
128+
details_fields.append(f'description: {t.check.descr}')
129+
details = '\n' + '\n'.join(f' {field}' for field in details_fields)
119130

120131
if concretized or (not concretized and
121132
t.check.unique_name not in unique_checks):
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import reframe as rfm
2+
import reframe.utility.sanity as sn
3+
4+
5+
@rfm.simple_test
6+
class TestWithDescription(rfm.RegressionTest):
7+
descr = 'Test with meaningful description'
8+
9+
valid_systems = ['*']
10+
valid_prog_environs = ['*']
11+
executable = 'echo'
12+
executable_opts = ['Hello with description']
13+
14+
@sanity_function
15+
def validate(self):
16+
return sn.assert_found(r'Hello', self.stdout)
17+
18+
19+
@rfm.simple_test
20+
class TestWithoutDescription(rfm.RegressionTest):
21+
# No descr attribute
22+
23+
valid_systems = ['*']
24+
valid_prog_environs = ['*']
25+
executable = 'echo'
26+
executable_opts = ['Hello without description']
27+
28+
@sanity_function
29+
def validate(self):
30+
return sn.assert_found(r'Hello', self.stdout)
31+
32+
33+
@rfm.simple_test
34+
class TestWithEmptyDescription(rfm.RegressionTest):
35+
descr = '' # Empty description
36+
37+
valid_systems = ['*']
38+
valid_prog_environs = ['*']
39+
executable = 'echo'
40+
executable_opts = ['Hello with empty description']
41+
42+
@sanity_function
43+
def validate(self):
44+
return sn.assert_found(r'Hello', self.stdout)

unittests/test_cli.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,63 @@ def test_list_with_details(run_reframe):
658658
assert returncode == 0
659659

660660

661+
def test_list_with_details_with_descr(run_reframe):
662+
returncode, stdout, stderr = run_reframe(
663+
checkpath=['unittests/resources/checks/descr_test.py'],
664+
action='list_detailed',
665+
more_options=['-n', 'TestWithDescription']
666+
)
667+
assert 'Traceback' not in stdout
668+
assert 'Traceback' not in stderr
669+
assert returncode == 0
670+
# Check that the description is shown for tests that have it
671+
assert 'description: Test with meaningful description' in stdout
672+
673+
674+
def test_list_with_details_with_empty_descr(run_reframe):
675+
returncode, stdout, stderr = run_reframe(
676+
checkpath=['unittests/resources/checks/descr_test.py'],
677+
action='list_detailed',
678+
more_options=['-n', 'TestWithEmptyDescription']
679+
)
680+
assert 'Traceback' not in stdout
681+
assert 'Traceback' not in stderr
682+
assert returncode == 0
683+
# Check that empty descr doesn't show a description line
684+
assert 'TestWithEmptyDescription' in stdout
685+
assert 'description:' not in stdout
686+
687+
688+
def test_list_with_details_without_descr(run_reframe):
689+
returncode, stdout, stderr = run_reframe(
690+
checkpath=['unittests/resources/checks/descr_test.py'],
691+
action='list_detailed',
692+
more_options=['-n', 'TestWithoutDescription']
693+
)
694+
assert 'Traceback' not in stdout
695+
assert 'Traceback' not in stderr
696+
assert returncode == 0
697+
# Check that no description line appears for tests without description
698+
assert 'TestWithoutDescription' in stdout
699+
assert 'description:' not in stdout
700+
701+
702+
def test_list_without_details_no_descr(run_reframe):
703+
returncode, stdout, stderr = run_reframe(
704+
checkpath=['unittests/resources/checks/descr_test.py'],
705+
action='list'
706+
)
707+
assert 'Traceback' not in stdout
708+
assert 'Traceback' not in stderr
709+
assert returncode == 0
710+
# Check that descriptions are not shown in non-detailed listing
711+
assert 'description:' not in stdout
712+
# But the test names should still be there
713+
assert 'TestWithDescription' in stdout
714+
assert 'TestWithoutDescription' in stdout
715+
assert 'TestWithEmptyDescription' in stdout
716+
717+
661718
def test_list_concretized(run_reframe):
662719
returncode, stdout, stderr = run_reframe(
663720
checkpath=['unittests/resources/checks/frontend_checks.py'],

0 commit comments

Comments
 (0)