Skip to content

Commit

Permalink
Override test attribute from plan
Browse files Browse the repository at this point in the history
New option for discover -h fmf to adjust discovered tests

Fix: #2430
  • Loading branch information
lukaszachy committed Apr 16, 2024
1 parent 22731b9 commit 8c719b9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
26 changes: 26 additions & 0 deletions tests/discover/adjust-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

rlJournalStart
rlPhaseStartSetup
rlRun "pushd data"
rlRun "run=\$(mktemp -d)"
rlPhaseEnd

rlPhaseStartTest
rlRun -s "tmt run -i $run discover plans --name /fmf/adjust-tests"
# If we ever change the path...
tests_yaml="$(find $run -name tests.yaml)"
rlAssertExits "$tests_yaml"
rlRun -s "yq '.[].require' < $tests_yaml"
rlAssertGrep "foo" "$rlRun_LOG"
rlRun -s "yq '.[].duration' < $tests_yaml"
# Note the space before 10.. duration is adjusted to the raw input ' 10h'
rlAssertGrep " 10h" "$rlRun_LOG"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "rm -rf $run"
rlRun "popd"
rlPhaseEnd
rlJournalEnd
8 changes: 8 additions & 0 deletions tests/discover/data/plans.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,11 @@ execute:
url: https://github.com/teemtee/tmt
how: fmf
ref: "@tests/discover/data/dynamic-ref.fmf"
/adjust-tests:
discover:
how: fmf
test: /tests/discover1
adjust-tests:
- duration+: " 10h"
- require+:
- foo
4 changes: 4 additions & 0 deletions tests/discover/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ tier: 3
/pruning:
summary: Test pruning was done for tests
test: ./prune.sh

/adjust-tests:
summary: Change test metadata within discover phase
test: ./adjust-tests.sh
5 changes: 4 additions & 1 deletion tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,7 @@ def __init__(self,
path: Optional[Path] = None,
tree: Optional[fmf.Tree] = None,
fmf_context: Optional[FmfContext] = None,
additional_rules: Optional[list[Any]] = None,
logger: tmt.log.Logger) -> None:
""" Initialize tmt tree from directory path or given fmf tree """

Expand All @@ -2725,6 +2726,7 @@ def __init__(self,
self._path = path or Path.cwd()
self._tree = tree
self._custom_fmf_context = fmf_context or FmfContext()
self._additional_rules = additional_rules

@classmethod
def grow(
Expand Down Expand Up @@ -2838,7 +2840,8 @@ def tree(self) -> fmf.Tree:
self._tree.adjust(
fmf.context.Context(**self._fmf_context),
case_sensitive=False,
decision_callback=create_adjust_callback(self._logger))
decision_callback=create_adjust_callback(self._logger),
additional_rules=self._additional_rules)
return self._tree

@tree.setter
Expand Down
9 changes: 8 additions & 1 deletion tmt/steps/discover/fmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ class DiscoverFmfStepData(tmt.steps.discover.DiscoverStepData):
show_default=True,
help="Copy only immediate directories of executed tests and their required files.")

# Edit discovered tests
adjust_tests: list[Any] = field(
multiple=True,
default_factory=list
)

# Upgrade plan path so the plan is not pruned
upgrade_path: Optional[str] = None

Expand Down Expand Up @@ -562,7 +568,8 @@ def do_the_discovery(self, path: Optional[Path] = None) -> None:
tree = tmt.Tree(
logger=self._logger,
path=tree_path,
fmf_context=self.step.plan._fmf_context)
fmf_context=self.step.plan._fmf_context,
additional_rules=self.get('adjust-tests'))
self._tests = tree.tests(
filters=filters,
names=names,
Expand Down

0 comments on commit 8c719b9

Please sign in to comment.