-
Notifications
You must be signed in to change notification settings - Fork 63
feat: add fixture to skip test according to rhoai version #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6f36ae1
feat: add fixture to skip test accoring to rhoai version
efd5c59
Merge branch 'main' into temp
mwaykole 7104caa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d02dcb1
feat: add fixture to skip test according to RHOAI csv version
7e20159
Merge branch 'main' into temp
mwaykole 105baee
feat: add fixture to skip test according to RHOAI csv version
3fc1413
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4175c6d
Merge branch 'main' into temp
mwaykole d2093bd
feat: add fixture to skip test according to RHOAI csv version
dfa6a44
feat: add fixture to skip test according to RHOAI csv version
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import pytest | ||
| from typing import Any | ||
| from simple_logger.logger import get_logger | ||
|
|
||
| LOGGER = get_logger(name=__name__) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def compare_versions(version1: str, version2: str) -> int: | ||
| """ | ||
| Compare two version strings. | ||
| Returns: -1 if version1 < version2, 0 if equal, 1 if version1 > version2 | ||
| """ | ||
| from packaging import version | ||
|
|
||
| try: | ||
| return (version.parse(version1) > version.parse(version2)) - (version.parse(version1) < version.parse(version2)) | ||
| except Exception as e: | ||
| LOGGER.error(f"[VERSION COMPARE] Error comparing versions: {e}") | ||
mwaykole marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return 0 | ||
|
|
||
|
|
||
| def skip_if_version_less_than(min_version: str) -> tuple[Any, ...]: | ||
| """ | ||
| Skip tests if version is less than specified minimum. | ||
|
|
||
| Works for both UPSTREAM and DOWNSTREAM distributions: | ||
| - DOWNSTREAM: Uses RHODS version checking | ||
| - UPSTREAM: Uses environment variable control | ||
|
|
||
| Usage: | ||
| pytestmark = [ | ||
| pytest.mark.serverless, | ||
| *skip_if_version_less_than("2.23.0"), | ||
| ] | ||
| Args: | ||
| min_version: Minimum required version (e.g., "2.23.0") | ||
|
|
||
| Returns: | ||
| Tuple of pytest marks for downstream OR skipif mark for upstream | ||
| """ | ||
| try: | ||
| from pytest_testconfig import config as py_config | ||
|
|
||
| distribution = py_config.get("distribution", "") | ||
|
|
||
| if distribution == "downstream": | ||
| # Use existing RHODS version checking fixtures | ||
| return ( | ||
| pytest.mark.parametrize("skip_if_downstream_version_less_than", [min_version], indirect=True), | ||
| pytest.mark.usefixtures("skip_if_downstream_version_less_than"), | ||
| ) | ||
| else: | ||
| # For non-downstream distributions, return empty tuple | ||
| return () | ||
| except Exception as e: | ||
| print(f"⚠️ Version check setup failed: {e}, proceeding with test") | ||
| return () | ||
|
|
||
|
|
||
| def skip_if_version_greater_than(max_version: str) -> tuple[Any, ...]: | ||
| """ | ||
| Skip tests if version is greater than specified maximum. | ||
|
|
||
| Usage: | ||
| pytestmark = [ | ||
| pytest.mark.serverless, | ||
| *skip_if_version_greater_than("2.25.0"), | ||
| ] | ||
|
|
||
| Args: | ||
| max_version: Maximum allowed version (e.g., "2.25.0") | ||
|
|
||
| Returns: | ||
| Tuple of pytest marks for downstream | ||
| """ | ||
| try: | ||
| from pytest_testconfig import config as py_config | ||
|
|
||
| distribution = py_config.get("distribution", "") | ||
|
|
||
| if distribution == "downstream": | ||
| # Use existing RHODS version checking fixtures | ||
| return ( | ||
| pytest.mark.parametrize("skip_if_downstream_version_greater_than", [max_version], indirect=True), | ||
| pytest.mark.usefixtures("skip_if_downstream_version_greater_than"), | ||
| ) | ||
| else: | ||
| # For non-downstream distributions, return empty tuple | ||
| return () | ||
| except Exception as e: | ||
| print(f"⚠️ Version check setup failed: {e}, proceeding with test") | ||
| return () | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this PR. We branch based on version. Why not remove not needed tests directly from the branches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but sometimes we submit a PR for an RHOAI N+2 branch feature that is expected to fail and create noise, since the dependent code from other components hasn't been merged yet. In such cases, this approach would be more efficient than manually adding or removing skip flags, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good idea. Your test branch should reflect associated product branch behavior. Adding programmatic skips is not a good idea. Please use jira marker or xfail.