Skip to content

Commit 9014d78

Browse files
committed
Preserve order of the shell discover tests
Tests defined using the `shell` discover method should be executed in the very same order as listed in the discover step config.
1 parent 7501a7b commit 9014d78

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

docs/releases.rst

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
======================
66

77

8+
tmt-1.41.0
9+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
11+
Tests defined using the :ref:`/plugins/discover/shell` discover
12+
method are now executed in the exact order as listed in the config
13+
file. This fixes a problem which has been introduced in the recent
14+
``fmf`` update.
15+
16+
817
tmt-1.40.0
918
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1019

tests/discover/order.sh

+18
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ EOF
177177
EOF
178178
run_test
179179

180+
# Tests defined using the 'shell' discover method should be
181+
# executed in the order provided in the config file
182+
183+
plan="/shell-preserve-order"
184+
185+
cat > $tmp/EXPECTED-DISCOVERY <<EOF
186+
/tests/one
187+
/tests/two
188+
/tests/three
189+
EOF
190+
191+
cat > $tmp/EXPECTED-EXECUTION <<EOF
192+
/guest/default-0/tests/one-1
193+
/guest/default-0/tests/two-2
194+
/guest/default-0/tests/three-3
195+
EOF
196+
run_test
197+
180198
rlPhaseStartCleanup
181199
rlRun 'rm -rf $tmp' 0 "Remove tmp directory"
182200
rlPhaseEnd

tests/discover/order/plans.fmf

+12
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,15 @@ finish:
9090
test: echo $TMT_TEST_DATA >> $TMT_PLAN_DATA/execution_order
9191
- name: /order-default
9292
test: echo $TMT_TEST_DATA >> $TMT_PLAN_DATA/execution_order
93+
94+
/shell-preserve-order:
95+
summary: Tests should run in the provided order
96+
discover:
97+
how: shell
98+
tests:
99+
- name: /tests/one
100+
test: echo $TMT_TEST_DATA >> $TMT_PLAN_DATA/execution_order
101+
- name: /tests/two
102+
test: echo $TMT_TEST_DATA >> $TMT_PLAN_DATA/execution_order
103+
- name: /tests/three
104+
test: echo $TMT_TEST_DATA >> $TMT_PLAN_DATA/execution_order

tmt/base.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -3033,7 +3033,8 @@ def tests(
30333033
unique: bool = True,
30343034
links: Optional[list['LinkNeedle']] = None,
30353035
excludes: Optional[list[str]] = None,
3036-
apply_command_line: bool = True
3036+
apply_command_line: bool = True,
3037+
sort: bool = True
30373038
) -> list[Test]:
30383039
""" Search available tests """
30393040
# Handle defaults, apply possible command line options
@@ -3076,8 +3077,8 @@ def name_filter(nodes: Iterable[fmf.Tree]) -> list[fmf.Tree]:
30763077

30773078
if Test._opt('source'):
30783079
tests = [
3079-
Test(node=test, logger=self._logger.descend()) for test in self.tree.prune(
3080-
keys=keys, sources=cmd_line_names)]
3080+
Test(node=test, logger=self._logger.descend())
3081+
for test in self.tree.prune(keys=keys, sources=cmd_line_names, sort=sort)]
30813082

30823083
elif not unique and names:
30833084
# First let's build the list of test objects based on keys & names.
@@ -3092,7 +3093,9 @@ def name_filter(nodes: Iterable[fmf.Tree]) -> list[fmf.Tree]:
30923093
logger=logger.descend(
30933094
logger_name=test.get('name', None)
30943095
) # .apply_verbosity_options(**self._options),
3095-
) for test in name_filter(self.tree.prune(keys=keys, names=[name]))]
3096+
) for test in name_filter(
3097+
self.tree.prune(keys=keys, names=[name], sort=sort))
3098+
]
30963099
tests.extend(sorted(selected_tests, key=lambda test: test.order))
30973100
# Otherwise just perform a regular key/name filtering
30983101
else:
@@ -3103,7 +3106,8 @@ def name_filter(nodes: Iterable[fmf.Tree]) -> list[fmf.Tree]:
31033106
logger=logger.descend(
31043107
logger_name=test.get('name', None)
31053108
) # .apply_verbosity_options(**self._options),
3106-
) for test in name_filter(self.tree.prune(keys=keys, names=names))]
3109+
) for test in name_filter(
3110+
self.tree.prune(keys=keys, names=names, sort=sort))]
31073111
tests = sorted(selected_tests, key=lambda test: test.order)
31083112

31093113
# Apply filters & conditions

tmt/steps/discover/shell.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
438438
self._tests = tmt.Tree(
439439
logger=self._logger,
440440
tree=tests).tests(
441-
conditions=["manual is False"])
441+
conditions=["manual is False"],
442+
sort=False)
442443

443444
# Propagate `where` key and TMT_SOURCE_DIR
444445
for test in self._tests:

0 commit comments

Comments
 (0)