File skip-certain-tests-if-necessary-and-mark-some-flaky-.patch of Package salt

From cbdac6efd56a48c41a4f9a86fafb4b874510d400 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Wed, 12 Jun 2024 09:38:43 +0100
Subject: [PATCH] Skip certain tests if necessary and mark some flaky
 ones (#657)

* Small alignments with upstream

* Skip tests if necessary and mark some flaky ones

* Add extra flaky test
---
 tests/integration/modules/test_status.py              |  1 +
 tests/pytests/functional/cache/test_consul.py         |  7 +------
 tests/pytests/functional/cache/test_mysql.py          |  6 +++---
 tests/pytests/functional/modules/state/test_state.py  |  5 +++++
 tests/pytests/functional/modules/test_pkg.py          |  8 ++++++++
 .../pytests/functional/modules/test_virtualenv_mod.py |  5 +++++
 tests/pytests/functional/states/file/test_managed.py  |  1 +
 tests/pytests/functional/states/pkgrepo/test_suse.py  | 10 ++++++++++
 tests/pytests/functional/states/test_pip_state.py     |  4 ++++
 tests/pytests/functional/states/test_user.py          | 11 ++++++++++-
 tests/pytests/integration/cli/test_syndic_eauth.py    |  2 --
 tests/pytests/integration/daemons/test_memory_leak.py |  2 +-
 tests/support/pytest/mysql.py                         |  8 ++++++++
 13 files changed, 57 insertions(+), 13 deletions(-)

diff --git a/tests/integration/modules/test_status.py b/tests/integration/modules/test_status.py
index 3574e23a3a..e8d1d928af 100644
--- a/tests/integration/modules/test_status.py
+++ b/tests/integration/modules/test_status.py
@@ -45,6 +45,7 @@ class StatusModuleTest(ModuleCase):
 
     @pytest.mark.slow_test
     @pytest.mark.skip_if_not_root
+    @pytest.mark.flaky(max_runs=4)
     def test_status_diskusage(self):
         """
         status.diskusage
diff --git a/tests/pytests/functional/cache/test_consul.py b/tests/pytests/functional/cache/test_consul.py
index c1e7f0c225..6d62932e5e 100644
--- a/tests/pytests/functional/cache/test_consul.py
+++ b/tests/pytests/functional/cache/test_consul.py
@@ -8,14 +8,13 @@ from saltfactories.utils import random_string
 
 import salt.cache
 import salt.loader
-from salt.utils.versions import Version
 from tests.pytests.functional.cache.helpers import run_common_cache_tests
 
 pytest.importorskip(
     "consul",
     reason="Please install python-consul package to use consul data cache driver",
 )
-docker = pytest.importorskip("docker")
+docker = pytest.importorskip("docker", minversion="4.0.0")
 
 log = logging.getLogger(__name__)
 
@@ -26,10 +25,6 @@ pytestmark = [
     pytest.mark.slow_test,
     pytest.mark.skip_if_binaries_missing("dockerd"),
     pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
-    pytest.mark.skipif(
-        Version(docker.__version__) < Version("4.0.0"),
-        reason="Test does not work in this version of docker-py",
-    ),
 ]
 
 
diff --git a/tests/pytests/functional/cache/test_mysql.py b/tests/pytests/functional/cache/test_mysql.py
index 93c6c7c6f6..6cf3cc4953 100644
--- a/tests/pytests/functional/cache/test_mysql.py
+++ b/tests/pytests/functional/cache/test_mysql.py
@@ -5,11 +5,12 @@ import pytest
 
 import salt.cache
 import salt.loader
+import salt.modules.mysql
 from salt.utils.versions import Version
 from tests.pytests.functional.cache.helpers import run_common_cache_tests
 from tests.support.pytest.mysql import *  # pylint: disable=wildcard-import,unused-wildcard-import
 
-docker = pytest.importorskip("docker")
+pytest.importorskip("docker", minversion="4.0.0")
 
 log = logging.getLogger(__name__)
 
@@ -20,8 +21,7 @@ pytestmark = [
     pytest.mark.skip_if_binaries_missing("dockerd"),
     pytest.mark.skipif(INSIDE_CONTAINER, reason="Cannot run in a container"),
     pytest.mark.skipif(
-        Version(docker.__version__) < Version("4.0.0"),
-        reason="Test does not work in this version of docker-py",
+        not salt.modules.mysql.MySQLdb, reason="Missing python MySQLdb library"
     ),
 ]
 
diff --git a/tests/pytests/functional/modules/state/test_state.py b/tests/pytests/functional/modules/state/test_state.py
index 32b811be1d..dd555efd00 100644
--- a/tests/pytests/functional/modules/state/test_state.py
+++ b/tests/pytests/functional/modules/state/test_state.py
@@ -750,6 +750,7 @@ def test_retry_option_success(state, state_tree, tmp_path):
 @pytest.mark.skip_on_windows(
     reason="Skipped until parallel states can be fixed on Windows"
 )
+@pytest.mark.xfail(reason="This test is flaky")
 def test_retry_option_success_parallel(state, state_tree, tmp_path):
     """
     test a state with the retry option that should return True immediately (i.e. no retries)
@@ -788,6 +789,8 @@ def test_retry_option_success_parallel(state, state_tree, tmp_path):
             assert "Attempt 2" not in state_return.comment
 
 
+@pytest.mark.slow_test
+@pytest.mark.xfail(reason="This test is flaky")
 def test_retry_option_eventual_success(state, state_tree, tmp_path):
     """
     test a state with the retry option that should return True, eventually
@@ -835,6 +838,8 @@ def test_retry_option_eventual_success(state, state_tree, tmp_path):
 @pytest.mark.skip_on_windows(
     reason="Skipped until parallel states can be fixed on Windows"
 )
+@pytest.mark.slow_test
+@pytest.mark.xfail(reason="This test is flaky")
 def test_retry_option_eventual_success_parallel(state, state_tree, tmp_path):
     """
     test a state with the retry option that should return True, eventually
diff --git a/tests/pytests/functional/modules/test_pkg.py b/tests/pytests/functional/modules/test_pkg.py
index 7566059023..4d76deba60 100644
--- a/tests/pytests/functional/modules/test_pkg.py
+++ b/tests/pytests/functional/modules/test_pkg.py
@@ -248,6 +248,10 @@ def test_which(modules, grains):
 @pytest.mark.requires_salt_modules("pkg.version", "pkg.install", "pkg.remove")
 @pytest.mark.slow_test
 @pytest.mark.requires_network
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_install_remove(modules, pkg_name):
     """
     successfully install and uninstall a package
@@ -289,6 +293,10 @@ def test_install_remove(modules, pkg_name):
 @pytest.mark.slow_test
 @pytest.mark.requires_network
 @pytest.mark.requires_salt_states("pkg.installed")
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_hold_unhold(grains, modules, states, pkg_name):
     """
     test holding and unholding a package
diff --git a/tests/pytests/functional/modules/test_virtualenv_mod.py b/tests/pytests/functional/modules/test_virtualenv_mod.py
index 7d8398e149..2b6abf91e2 100644
--- a/tests/pytests/functional/modules/test_virtualenv_mod.py
+++ b/tests/pytests/functional/modules/test_virtualenv_mod.py
@@ -2,6 +2,7 @@ import shutil
 
 import pytest
 
+import salt.utils.path
 from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
 
 pytestmark = [
@@ -63,6 +64,10 @@ def test_clear(virtualenv, venv_dir, modules):
     assert "pep8" not in packages
 
 
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_virtualenv_ver(virtualenv, venv_dir):
     ret = virtualenv.create(str(venv_dir))
     assert ret
diff --git a/tests/pytests/functional/states/file/test_managed.py b/tests/pytests/functional/states/file/test_managed.py
index 6e1aa4b3a9..47fbab198d 100644
--- a/tests/pytests/functional/states/file/test_managed.py
+++ b/tests/pytests/functional/states/file/test_managed.py
@@ -904,6 +904,7 @@ def test_file_managed_keep_source_false_http(
 
 
 @pytest.mark.parametrize("verify_ssl", [True, False])
+@pytest.mark.flaky(max_runs=4)
 def test_verify_ssl_https_source(file, tmp_path, ssl_webserver, verify_ssl):
     """
     test verify_ssl when its False and True when managing
diff --git a/tests/pytests/functional/states/pkgrepo/test_suse.py b/tests/pytests/functional/states/pkgrepo/test_suse.py
index 19ba928ce6..3bafeedc94 100644
--- a/tests/pytests/functional/states/pkgrepo/test_suse.py
+++ b/tests/pytests/functional/states/pkgrepo/test_suse.py
@@ -1,5 +1,7 @@
 import pytest
 
+import salt.utils.path
+
 pytestmark = [
     pytest.mark.destructive_test,
     pytest.mark.skip_if_not_root,
@@ -80,6 +82,10 @@ def suse_state_tree(grains, pkgrepo, state_tree):
 
 
 @pytest.mark.requires_salt_states("pkgrepo.managed", "pkgrepo.absent")
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_pkgrepo_managed_absent(grains, modules, subtests, suse_state_tree):
     """
     Test adding and removing a repository
@@ -134,6 +140,10 @@ def test_pkgrepo_managed_absent(grains, modules, subtests, suse_state_tree):
 
 
 @pytest.mark.requires_salt_states("pkgrepo.managed")
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_pkgrepo_managed_modify(grains, modules, subtests, suse_state_tree):
     """
     Test adding and modifying a repository
diff --git a/tests/pytests/functional/states/test_pip_state.py b/tests/pytests/functional/states/test_pip_state.py
index 84bca06924..1300f41964 100644
--- a/tests/pytests/functional/states/test_pip_state.py
+++ b/tests/pytests/functional/states/test_pip_state.py
@@ -106,6 +106,10 @@ def _skip_if_pep8_installed(modules, pkg_name):
 
 @pytest.mark.slow_test
 @pytest.mark.usefixtures("_skip_if_pep8_installed")
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_pip_installed_removed(states, pkg_name):
     """
     Tests installed and removed states
diff --git a/tests/pytests/functional/states/test_user.py b/tests/pytests/functional/states/test_user.py
index 28be3cd861..5db781548b 100644
--- a/tests/pytests/functional/states/test_user.py
+++ b/tests/pytests/functional/states/test_user.py
@@ -14,6 +14,7 @@ import pytest
 from saltfactories.utils import random_string
 
 import salt.utils.files
+import salt.utils.path
 import salt.utils.platform
 
 try:
@@ -143,7 +144,7 @@ def test_user_present_nondefault(grains, modules, states, username, user_home):
     if not salt.utils.platform.is_darwin() and not salt.utils.platform.is_windows():
         assert user_home.is_dir()
 
-    if grains["os_family"] in ("Suse",):
+    if grains["os_family"] in ("Suse",) and not grains.get("transactional", False):
         expected_group_name = "users"
     elif grains["os_family"] == "MacOS":
         expected_group_name = "staff"
@@ -386,6 +387,10 @@ def test_user_present_existing(states, username):
 
 
 @pytest.mark.skip_unless_on_linux(reason="underlying functionality only runs on Linux")
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_user_present_change_groups(modules, states, username, group_1, group_2):
     ret = states.user.present(
         name=username,
@@ -410,6 +415,10 @@ def test_user_present_change_groups(modules, states, username, group_1, group_2)
 
 
 @pytest.mark.skip_unless_on_linux(reason="underlying functionality only runs on Linux")
+@pytest.mark.skipif(
+    bool(salt.utils.path.which("transactional-update")),
+    reason="Skipping on transactional systems",
+)
 def test_user_present_change_optional_groups(
     modules, states, username, group_1, group_2
 ):
diff --git a/tests/pytests/integration/cli/test_syndic_eauth.py b/tests/pytests/integration/cli/test_syndic_eauth.py
index d59014c491..451feb5de9 100644
--- a/tests/pytests/integration/cli/test_syndic_eauth.py
+++ b/tests/pytests/integration/cli/test_syndic_eauth.py
@@ -7,8 +7,6 @@ import time
 
 import pytest
 
-from tests.conftest import CODE_DIR
-
 docker = pytest.importorskip("docker", minversion="4.0.0")
 
 log = logging.getLogger(__name__)
diff --git a/tests/pytests/integration/daemons/test_memory_leak.py b/tests/pytests/integration/daemons/test_memory_leak.py
index f5af28029c..5de8e60a06 100644
--- a/tests/pytests/integration/daemons/test_memory_leak.py
+++ b/tests/pytests/integration/daemons/test_memory_leak.py
@@ -56,7 +56,7 @@ def file_add_delete_sls(tmp_path, salt_master):
 @pytest.mark.skip(reason="Flawed test")
 @pytest.mark.skip_on_darwin(reason="MacOS is a spawning platform, won't work")
 @pytest.mark.skipif(GITHUB_ACTIONS, reason="Test is failing in GitHub Actions")
-@pytest.mark.flaky(max_runs=10)
+@pytest.mark.xfail(reason="This test is flaky")
 def test_memory_leak(salt_cli, salt_minion, file_add_delete_sls):
     max_usg = None
 
diff --git a/tests/support/pytest/mysql.py b/tests/support/pytest/mysql.py
index 20377e3453..bb8cc6d700 100644
--- a/tests/support/pytest/mysql.py
+++ b/tests/support/pytest/mysql.py
@@ -6,11 +6,19 @@ import pytest
 from pytestskipmarkers.utils import platform
 from saltfactories.utils import random_string
 
+import salt.modules.mysql
+
 # This `pytest.importorskip` here actually works because this module
 # is imported into test modules, otherwise, the skipping would just fail
 pytest.importorskip("docker")
 import docker.errors  # isort:skip  pylint: disable=3rd-party-module-not-gated
 
+pytestmark = [
+    pytest.mark.skipif(
+        not salt.modules.mysql.MySQLdb, reason="Missing python MySQLdb library"
+    )
+]
+
 log = logging.getLogger(__name__)
 
 
-- 
2.47.0

openSUSE Build Service is sponsored by