Skip to content

Commit

Permalink
squash: address upgrade tests
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Sep 24, 2024
1 parent 6a2f9b0 commit 1b3af69
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
43 changes: 37 additions & 6 deletions tmt/steps/discover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,32 @@ def tests(
self,
*,
phase_name: Optional[str] = None,
enabled: Optional[bool] = None) -> list['tmt.Test']:
enabled: Optional[bool] = None) -> list[tuple[str, 'tmt.Test']]:
"""
Return discovered tests
Each DiscoverPlugin has to implement this method.
Should return a list of Test() objects.
Return discovered tests.
:param phase_name: if set, return only tests discovered by the
phase of this name. Otherwise, all tests discovered by the
phase are returned.
.. note::
This parameter exists to present unified interface with
:py:meth:`tmt.steps.discover.Discover.tests` API, but it
has no interesting effect in case of individual phases:
* left unset, all tests discovered by the phase are
returned,
* set to a phase name, tests discovered by that phase
should be returned. But a phase does not have access to
other phases' tests, therefore setting it to anything
but this phase name would produce an empty list.
:param enabled: if set, return only tests that are enabled
(``enabled=True``) or disabled (``enabled=False``). Otherwise,
all tests are returned.
:returns: a list of phase name and test pairs.
"""

raise NotImplementedError

def download_distgit_source(
Expand Down Expand Up @@ -354,7 +373,7 @@ def go(self, force: bool = False) -> None:
# Prefix test name only if multiple plugins configured
prefix = f'/{phase.name}' if len(self.phases()) > 1 else ''
# Check discovered tests, modify test name/path
for test in phase.tests(enabled=True):
for _, test in phase.tests(enabled=True):
test.name = f"{prefix}{test.name}"
test.path = Path(f"/{phase.safe_name}{test.path}")
# Update test environment with plan environment
Expand Down Expand Up @@ -421,6 +440,18 @@ def tests(
*,
phase_name: Optional[str] = None,
enabled: Optional[bool] = None) -> list[tuple[str, 'tmt.Test']]:
"""
Return discovered tests.
:param phase_name: if set, return only tests discovered by the
phase of this name. Otherwise, tests discovered by all
phases are returned.
:param enabled: if set, return only tests that are enabled
(``enabled=True``) or disabled (``enabled=False``). Otherwise,
all tests are returned.
:returns: a list of phase name and test pairs.
"""

suitable_tests = self._failed_tests if self._failed_tests else self._tests
suitable_phases = [phase_name] if phase_name is not None else list(self._tests.keys())

Expand Down
9 changes: 4 additions & 5 deletions tmt/steps/discover/fmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def post_dist_git(self, created_content: list[Path]) -> None:
# Prefix test name only if multiple plugins configured
prefix = f'/{self.name}' if len(self.step.phases()) > 1 else ''
# Check discovered tests, modify test name/path
for test in self.tests(enabled=True):
for _, test in self.tests(enabled=True):
test.name = f"{prefix}{test.name}"
test.path = Path(f"/{self.safe_name}{test.path}")
# Update test environment with plan environment
Expand All @@ -738,13 +738,12 @@ def tests(
self,
*,
phase_name: Optional[str] = None,
enabled: Optional[bool] = None) -> list['tmt.Test']:
""" Return all discovered tests """
enabled: Optional[bool] = None) -> list[tuple[str, 'tmt.Test']]:

if phase_name is not None and phase_name != self.name:
return []

if enabled is None:
return self._tests
return [(self.name, test) for test in self._tests]

return [test for test in self._tests if test.enabled is enabled]
return [(self.name, test) for test in self._tests if test.enabled is enabled]
6 changes: 3 additions & 3 deletions tmt/steps/discover/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,12 @@ def tests(
self,
*,
phase_name: Optional[str] = None,
enabled: Optional[bool] = None) -> list['tmt.Test']:
enabled: Optional[bool] = None) -> list[tuple[str, 'tmt.Test']]:

if phase_name is not None and phase_name != self.name:
return []

if enabled is None:
return self._tests
return [(self.name, test) for test in self._tests]

return [test for test in self._tests if test.enabled is enabled]
return [(self.name, test) for test in self._tests if test.enabled is enabled]
7 changes: 3 additions & 4 deletions tmt/steps/execute/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def _perform_upgrade(

required_packages: list[tmt.base.DependencySimple] = []
recommended_packages: list[tmt.base.DependencySimple] = []
for test in self._discover_upgrade.tests(enabled=True):
for _, test in self._discover_upgrade.tests(enabled=True):
test.name = f'/{DURING_UPGRADE_PREFIX}/{test.name.lstrip("/")}'

# Gathering dependencies for upgrade tasks
Expand Down Expand Up @@ -386,7 +386,7 @@ def _run_test_phase(
The prefix is also set as IN_PLACE_UPGRADE environment variable.
"""
names_backup = []
for _, test in cast(list[tuple[str, tmt.base.Test]], self.discover.tests(enabled=True)):
for _, test in self.discover.tests(enabled=True):
names_backup.append(test.name)
test.name = f'/{prefix}/{test.name.lstrip("/")}'

Expand All @@ -395,6 +395,5 @@ def _run_test_phase(
extra_environment=Environment({STATUS_VARIABLE: EnvVarValue(prefix)}),
logger=logger)

tests = cast(list[tuple[str, tmt.base.Test]], self.discover.tests(enabled=True))
for i, (_, test) in enumerate(tests):
for i, (_, test) in enumerate(self.discover.tests(enabled=True)):
test.name = names_backup[i]

0 comments on commit 1b3af69

Please sign in to comment.