File fix-tests-failures-and-errors-when-detected-on-vm-ex.patch of Package salt

From a0cda56ec5861e62976dad7f05f207f4a3b54224 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Thu, 14 Mar 2024 13:03:00 +0000
Subject: [PATCH] Fix tests failures and errors when detected on VM
 execution from Salt Shaker (#636)

* test_chmod: fix test expectation

* test_pkg: Adjust package expectation for SUSE family

* test_docker_network: Skip non-supported operation for SUSE family

* Fix tests failing due wrong docker-py version

* test_version: skip test in packaged scenario when setup.py is missing

* Fix issue related to docker version used during testing

* Fix test errors when setup.py is not available

* test_loader: do not run if setup.py is missing

* test_install: Fix test errors when setup.py is not available

* test_master: use a right service name expected on SUSE family

* test_jinja_filters: prevent test failure when which binary is not available

* Prevent errors when x509 utils cannot be loaded

* test_thin: skip test if virtualenv binary is missing
---
 tests/integration/pillar/test_git_pillar.py      | 12 +++++++++++-
 tests/pytests/functional/cache/test_consul.py    |  5 +++++
 tests/pytests/functional/cache/test_mysql.py     |  5 +++++
 tests/pytests/functional/loader/test_loader.py   |  9 +++++++++
 .../modules/state/test_jinja_filters.py          |  4 ++--
 tests/pytests/functional/modules/test_pkg.py     |  2 ++
 .../functional/states/rabbitmq/conftest.py       | 11 +++++++++++
 .../functional/states/rabbitmq/test_cluster.py   |  7 ++++++-
 .../functional/states/rabbitmq/test_plugin.py    |  8 +++++++-
 .../functional/states/rabbitmq/test_policy.py    |  7 ++++++-
 .../functional/states/rabbitmq/test_upstream.py  |  7 ++++++-
 .../functional/states/rabbitmq/test_user.py      |  7 ++++++-
 .../functional/states/rabbitmq/test_vhost.py     |  7 ++++++-
 tests/pytests/functional/states/test_pkg.py      |  2 +-
 tests/pytests/functional/test_version.py         |  9 +++++++++
 .../pytests/integration/modules/test_x509_v2.py  |  2 +-
 tests/pytests/integration/ssh/test_log.py        |  7 ++++++-
 tests/pytests/integration/ssh/test_master.py     |  2 +-
 .../pytests/integration/ssh/test_py_versions.py  |  7 ++++++-
 tests/pytests/integration/ssh/test_ssh_setup.py  |  7 ++++++-
 tests/pytests/integration/states/test_x509_v2.py |  2 +-
 tests/pytests/scenarios/setup/test_install.py    |  8 ++++++++
 tests/pytests/unit/modules/test_pip.py           |  8 ++++++++
 tests/pytests/unit/utils/test_x509.py            | 16 +++++++++++++++-
 tests/unit/states/test_pip_state.py              |  6 ++++++
 tests/unit/utils/test_thin.py                    |  3 +++
 26 files changed, 153 insertions(+), 17 deletions(-)

diff --git a/tests/integration/pillar/test_git_pillar.py b/tests/integration/pillar/test_git_pillar.py
index 2a21296712..d47a0b6bbf 100644
--- a/tests/integration/pillar/test_git_pillar.py
+++ b/tests/integration/pillar/test_git_pillar.py
@@ -79,6 +79,7 @@ from salt.utils.gitfs import (
     PYGIT2_VERSION,
     FileserverConfigError,
 )
+from salt.utils.versions import Version
 from tests.support.gitfs import (  # pylint: disable=unused-import
     PASSWORD,
     USERNAME,
@@ -101,11 +102,20 @@ try:
 except Exception:  # pylint: disable=broad-except
     HAS_PYGIT2 = False
 
+docker = pytest.importorskip("docker")
+
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
+
 pytestmark = [
     SKIP_INITIAL_PHOTONOS_FAILURES,
     pytest.mark.skip_on_platforms(windows=True, darwin=True),
-    pytest.mark.skipif(INSIDE_CONTAINER, reason="Communication problems between containers."),
+    pytest.mark.skipif(
+        INSIDE_CONTAINER, reason="Communication problems between containers."
+    ),
+    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_consul.py b/tests/pytests/functional/cache/test_consul.py
index 14f9fa340d..460928d850 100644
--- a/tests/pytests/functional/cache/test_consul.py
+++ b/tests/pytests/functional/cache/test_consul.py
@@ -8,6 +8,7 @@ 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
 
 docker = pytest.importorskip("docker")
@@ -21,6 +22,10 @@ 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 e15fc732a4..93c6c7c6f6 100644
--- a/tests/pytests/functional/cache/test_mysql.py
+++ b/tests/pytests/functional/cache/test_mysql.py
@@ -5,6 +5,7 @@ import pytest
 
 import salt.cache
 import salt.loader
+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
 
@@ -18,6 +19,10 @@ 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/loader/test_loader.py b/tests/pytests/functional/loader/test_loader.py
index f34ca2239c..6e7889b712 100644
--- a/tests/pytests/functional/loader/test_loader.py
+++ b/tests/pytests/functional/loader/test_loader.py
@@ -1,15 +1,24 @@
 import json
+import os
 
 import pytest
 
 from salt.utils.versions import Version
 from tests.support.helpers import SaltVirtualEnv
 from tests.support.pytest.helpers import FakeSaltExtension
+from tests.support.runtests import RUNTIME_VARS
+
+MISSING_SETUP_PY_FILE = not os.path.exists(
+    os.path.join(RUNTIME_VARS.CODE_DIR, "setup.py")
+)
 
 pytestmark = [
     # These are slow because they create a virtualenv and install salt in it
     pytest.mark.slow_test,
     pytest.mark.timeout_unless_on_windows(240),
+    pytest.mark.skipif(
+        MISSING_SETUP_PY_FILE, reason="This test only work if setup.py is available"
+    ),
 ]
 
 
diff --git a/tests/pytests/functional/modules/state/test_jinja_filters.py b/tests/pytests/functional/modules/state/test_jinja_filters.py
index 7a72ba7f53..1c4910fc2a 100644
--- a/tests/pytests/functional/modules/state/test_jinja_filters.py
+++ b/tests/pytests/functional/modules/state/test_jinja_filters.py
@@ -987,9 +987,9 @@ def _filter_id(value):
         ),
         Filter(
             name="which",
-            expected={"ret": salt.utils.path.which("which")},
+            expected={"ret": salt.utils.path.which("ls")},
             sls="""
-            {% set result = 'which' | which() %}
+            {% set result = 'ls' | which() %}
             test:
               module.run:
                 - name: test.echo
diff --git a/tests/pytests/functional/modules/test_pkg.py b/tests/pytests/functional/modules/test_pkg.py
index 4899851efb..7566059023 100644
--- a/tests/pytests/functional/modules/test_pkg.py
+++ b/tests/pytests/functional/modules/test_pkg.py
@@ -72,6 +72,8 @@ def pkg_name(grains):
             _pkg = "units"
     elif grains["os_family"] == "Debian":
         _pkg = "ifenslave"
+    elif grains["os_family"] == "Suse":
+        _pkg = "wget"
     return _pkg
 
 
diff --git a/tests/pytests/functional/states/rabbitmq/conftest.py b/tests/pytests/functional/states/rabbitmq/conftest.py
index cc667939f5..e5bd091ad5 100644
--- a/tests/pytests/functional/states/rabbitmq/conftest.py
+++ b/tests/pytests/functional/states/rabbitmq/conftest.py
@@ -5,8 +5,19 @@ import attr
 import pytest
 from saltfactories.utils import random_string
 
+from salt.utils.versions import Version
+
 log = logging.getLogger(__name__)
 
+docker = pytest.importorskip("docker")
+
+pytestmark = [
+    pytest.mark.skipif(
+        Version(docker.__version__) < Version("4.0.0"),
+        reason="Test does not work in this version of docker-py",
+    ),
+]
+
 
 @attr.s(kw_only=True, slots=True)
 class RabbitMQImage:
diff --git a/tests/pytests/functional/states/rabbitmq/test_cluster.py b/tests/pytests/functional/states/rabbitmq/test_cluster.py
index 210b22a236..df85f04f78 100644
--- a/tests/pytests/functional/states/rabbitmq/test_cluster.py
+++ b/tests/pytests/functional/states/rabbitmq/test_cluster.py
@@ -9,8 +9,9 @@ import pytest
 
 import salt.modules.rabbitmq as rabbitmq
 import salt.states.rabbitmq_cluster as rabbitmq_cluster
+from salt.utils.versions import Version
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 log = logging.getLogger(__name__)
 
@@ -22,6 +23,10 @@ pytestmark = [
         "docker", "dockerd", reason="Docker not installed"
     ),
     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/states/rabbitmq/test_plugin.py b/tests/pytests/functional/states/rabbitmq/test_plugin.py
index f119149053..6ed4cdc923 100644
--- a/tests/pytests/functional/states/rabbitmq/test_plugin.py
+++ b/tests/pytests/functional/states/rabbitmq/test_plugin.py
@@ -9,11 +9,13 @@ import pytest
 
 import salt.modules.rabbitmq as rabbitmq
 import salt.states.rabbitmq_plugin as rabbitmq_plugin
+from salt.utils.versions import Version
 from tests.support.mock import patch
 
 log = logging.getLogger(__name__)
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
+
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -23,6 +25,10 @@ pytestmark = [
         "docker", "dockerd", reason="Docker not installed"
     ),
     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/states/rabbitmq/test_policy.py b/tests/pytests/functional/states/rabbitmq/test_policy.py
index 7ccf6a522e..c648c9ff94 100644
--- a/tests/pytests/functional/states/rabbitmq/test_policy.py
+++ b/tests/pytests/functional/states/rabbitmq/test_policy.py
@@ -9,11 +9,12 @@ import pytest
 
 import salt.modules.rabbitmq as rabbitmq
 import salt.states.rabbitmq_policy as rabbitmq_policy
+from salt.utils.versions import Version
 from tests.support.mock import MagicMock, patch
 
 log = logging.getLogger(__name__)
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -23,6 +24,10 @@ pytestmark = [
         "docker", "dockerd", reason="Docker not installed"
     ),
     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/states/rabbitmq/test_upstream.py b/tests/pytests/functional/states/rabbitmq/test_upstream.py
index c7bcf3b0d4..0a9686d694 100644
--- a/tests/pytests/functional/states/rabbitmq/test_upstream.py
+++ b/tests/pytests/functional/states/rabbitmq/test_upstream.py
@@ -9,10 +9,11 @@ import pytest
 
 import salt.modules.rabbitmq as rabbitmq
 import salt.states.rabbitmq_upstream as rabbitmq_upstream
+from salt.utils.versions import Version
 
 log = logging.getLogger(__name__)
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -22,6 +23,10 @@ pytestmark = [
         "docker", "dockerd", reason="Docker not installed"
     ),
     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/states/rabbitmq/test_user.py b/tests/pytests/functional/states/rabbitmq/test_user.py
index 31723df7be..a6b0766087 100644
--- a/tests/pytests/functional/states/rabbitmq/test_user.py
+++ b/tests/pytests/functional/states/rabbitmq/test_user.py
@@ -9,10 +9,11 @@ import pytest
 
 import salt.modules.rabbitmq as rabbitmq
 import salt.states.rabbitmq_user as rabbitmq_user
+from salt.utils.versions import Version
 
 log = logging.getLogger(__name__)
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -22,6 +23,10 @@ pytestmark = [
         "docker", "dockerd", reason="Docker not installed"
     ),
     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/states/rabbitmq/test_vhost.py b/tests/pytests/functional/states/rabbitmq/test_vhost.py
index d6ac6901a2..f3553c03e5 100644
--- a/tests/pytests/functional/states/rabbitmq/test_vhost.py
+++ b/tests/pytests/functional/states/rabbitmq/test_vhost.py
@@ -9,10 +9,11 @@ import pytest
 
 import salt.modules.rabbitmq as rabbitmq
 import salt.states.rabbitmq_vhost as rabbitmq_vhost
+from salt.utils.versions import Version
 
 log = logging.getLogger(__name__)
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -22,6 +23,10 @@ pytestmark = [
         "docker", "dockerd", reason="Docker not installed"
     ),
     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/states/test_pkg.py b/tests/pytests/functional/states/test_pkg.py
index 29fe757db2..68b2cb843d 100644
--- a/tests/pytests/functional/states/test_pkg.py
+++ b/tests/pytests/functional/states/test_pkg.py
@@ -73,7 +73,7 @@ def PKG_TARGETS(grains):
         else:
             _PKG_TARGETS = ["units", "zsh-html"]
     elif grains["os_family"] == "Suse":
-        _PKG_TARGETS = ["lynx", "htop"]
+        _PKG_TARGETS = ["iotop", "screen"]
     return _PKG_TARGETS
 
 
diff --git a/tests/pytests/functional/test_version.py b/tests/pytests/functional/test_version.py
index 1c198abce7..ecbd2ed51e 100644
--- a/tests/pytests/functional/test_version.py
+++ b/tests/pytests/functional/test_version.py
@@ -1,15 +1,24 @@
 import json
 import logging
+import os
 
 import pytest
 
 from tests.support.helpers import SaltVirtualEnv
 from tests.support.pytest.helpers import FakeSaltExtension
+from tests.support.runtests import RUNTIME_VARS
+
+MISSING_SETUP_PY_FILE = not os.path.exists(
+    os.path.join(RUNTIME_VARS.CODE_DIR, "setup.py")
+)
 
 pytestmark = [
     # These are slow because they create a virtualenv and install salt in it
     pytest.mark.slow_test,
     pytest.mark.timeout_unless_on_windows(240),
+    pytest.mark.skipif(
+        MISSING_SETUP_PY_FILE, reason="This test only work if setup.py is available"
+    ),
 ]
 
 log = logging.getLogger(__name__)
diff --git a/tests/pytests/integration/modules/test_x509_v2.py b/tests/pytests/integration/modules/test_x509_v2.py
index 09448135b8..7707652003 100644
--- a/tests/pytests/integration/modules/test_x509_v2.py
+++ b/tests/pytests/integration/modules/test_x509_v2.py
@@ -11,8 +11,8 @@ from pathlib import Path
 import pytest
 from saltfactories.utils import random_string
 
-import salt.utils.x509 as x509util
 from tests.conftest import FIPS_TESTRUN
+x509util = pytest.importorskip("salt.utils.x509")
 
 try:
     import cryptography
diff --git a/tests/pytests/integration/ssh/test_log.py b/tests/pytests/integration/ssh/test_log.py
index 686ff4a363..9573c9df05 100644
--- a/tests/pytests/integration/ssh/test_log.py
+++ b/tests/pytests/integration/ssh/test_log.py
@@ -9,9 +9,10 @@ import time
 import pytest
 from saltfactories.utils import random_string
 
+from salt.utils.versions import Version
 from tests.support.helpers import Keys
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -21,6 +22,10 @@ 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/integration/ssh/test_master.py b/tests/pytests/integration/ssh/test_master.py
index 94f4a2093f..ff2c56d24b 100644
--- a/tests/pytests/integration/ssh/test_master.py
+++ b/tests/pytests/integration/ssh/test_master.py
@@ -23,7 +23,7 @@ def test_service(salt_ssh_cli, grains):
     os_release = grains["osrelease"]
     if os_family == "RedHat":
         service = "crond"
-    elif os_family == "Arch":
+    elif os_family in ["Suse", "Arch"]:
         service = "sshd"
     elif os_family == "MacOS":
         service = "org.ntp.ntpd"
diff --git a/tests/pytests/integration/ssh/test_py_versions.py b/tests/pytests/integration/ssh/test_py_versions.py
index b77aba0bb7..e671c543db 100644
--- a/tests/pytests/integration/ssh/test_py_versions.py
+++ b/tests/pytests/integration/ssh/test_py_versions.py
@@ -10,9 +10,10 @@ import time
 import pytest
 from saltfactories.utils import random_string
 
+from salt.utils.versions import Version
 from tests.support.helpers import Keys
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -22,6 +23,10 @@ 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/integration/ssh/test_ssh_setup.py b/tests/pytests/integration/ssh/test_ssh_setup.py
index 94182d03ae..b4a16198a7 100644
--- a/tests/pytests/integration/ssh/test_ssh_setup.py
+++ b/tests/pytests/integration/ssh/test_ssh_setup.py
@@ -14,9 +14,10 @@ import pytest
 from pytestshellutils.utils.processes import ProcessResult, terminate_process
 from saltfactories.utils import random_string
 
+from salt.utils.versions import Version
 from tests.support.helpers import Keys
 
-pytest.importorskip("docker")
+docker = pytest.importorskip("docker")
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
@@ -26,6 +27,10 @@ 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/integration/states/test_x509_v2.py b/tests/pytests/integration/states/test_x509_v2.py
index 05889c08a5..eaded27610 100644
--- a/tests/pytests/integration/states/test_x509_v2.py
+++ b/tests/pytests/integration/states/test_x509_v2.py
@@ -10,8 +10,8 @@ from pathlib import Path
 import pytest
 from saltfactories.utils import random_string
 
-import salt.utils.x509 as x509util
 from tests.conftest import FIPS_TESTRUN
+x509util = pytest.importorskip("salt.utils.x509")
 
 try:
     import cryptography
diff --git a/tests/pytests/scenarios/setup/test_install.py b/tests/pytests/scenarios/setup/test_install.py
index a4494ce08f..d5d9afb23d 100644
--- a/tests/pytests/scenarios/setup/test_install.py
+++ b/tests/pytests/scenarios/setup/test_install.py
@@ -16,11 +16,16 @@ import salt.utils.path
 import salt.utils.platform
 import salt.version
 from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
+from tests.support.runtests import RUNTIME_VARS
 
 log = logging.getLogger(__name__)
 
 INSIDE_CONTAINER = os.getenv("HOSTNAME", "") == "salt-test-container"
 
+MISSING_SETUP_PY_FILE = not os.path.exists(
+    os.path.join(RUNTIME_VARS.CODE_DIR, "setup.py")
+)
+
 pytestmark = [
     pytest.mark.core_test,
     pytest.mark.windows_whitelisted,
@@ -29,6 +34,9 @@ pytestmark = [
     pytest.mark.skipif(
         INSIDE_CONTAINER, reason="No gcc and python3-devel in container."
     ),
+    pytest.mark.skipif(
+        MISSING_SETUP_PY_FILE, reason="This test only work if setup.py is available"
+    ),
 ]
 
 
diff --git a/tests/pytests/unit/modules/test_pip.py b/tests/pytests/unit/modules/test_pip.py
index b2b5a8988d..1991b551a3 100644
--- a/tests/pytests/unit/modules/test_pip.py
+++ b/tests/pytests/unit/modules/test_pip.py
@@ -9,6 +9,11 @@ import salt.utils.files
 import salt.utils.platform
 from salt.exceptions import CommandExecutionError
 from tests.support.mock import MagicMock, patch
+from tests.support.runtests import RUNTIME_VARS
+
+MISSING_SETUP_PY_FILE = not os.path.exists(
+    os.path.join(RUNTIME_VARS.CODE_DIR, "setup.py")
+)
 
 
 class FakeFopen:
@@ -1737,6 +1742,9 @@ def test_when_version_is_called_with_a_user_it_should_be_passed_to_undelying_run
         )
 
 
+@pytest.mark.skipif(
+    MISSING_SETUP_PY_FILE, reason="This test only work if setup.py is available"
+)
 @pytest.mark.parametrize(
     "bin_env,target,target_env,expected_target",
     [
diff --git a/tests/pytests/unit/utils/test_x509.py b/tests/pytests/unit/utils/test_x509.py
index 2efa3292e3..6a9728f3c8 100644
--- a/tests/pytests/unit/utils/test_x509.py
+++ b/tests/pytests/unit/utils/test_x509.py
@@ -4,7 +4,6 @@ from datetime import datetime, timedelta, timezone
 import pytest
 
 import salt.exceptions
-import salt.utils.x509 as x509
 from tests.support.mock import ANY, Mock, patch
 
 cryptography = pytest.importorskip(
@@ -14,6 +13,21 @@ cx509 = pytest.importorskip("cryptography.x509", reason="Needs cryptography libr
 cprim = pytest.importorskip(
     "cryptography.hazmat.primitives", reason="Needs cryptography library"
 )
+x509 = pytest.importorskip("salt.utils.x509")
+
+try:
+    import cryptography
+    import cryptography.x509 as cx509
+
+    HAS_LIBS = True
+except ImportError:
+    HAS_LIBS = False
+
+pytestmark = [
+    pytest.mark.skipif(HAS_LIBS is False, reason="Needs cryptography library")
+]
+
+CRYPTOGRAPHY_VERSION = tuple(int(x) for x in cryptography.__version__.split("."))
 
 
 @pytest.fixture
diff --git a/tests/unit/states/test_pip_state.py b/tests/unit/states/test_pip_state.py
index 211c4e95f4..565f26b046 100644
--- a/tests/unit/states/test_pip_state.py
+++ b/tests/unit/states/test_pip_state.py
@@ -14,6 +14,9 @@ from tests.support.unit import TestCase
 
 pip = pytest.importorskip(
     "pip", reason="The 'pip' library is not importable(installed system-wide)"
+
+MISSING_SETUP_PY_FILE = not os.path.exists(
+    os.path.join(RUNTIME_VARS.CODE_DIR, "setup.py")
 )
 
 log = logging.getLogger(__name__)
@@ -411,6 +414,9 @@ class PipStateUtilsTest(TestCase):
 
 @pytest.mark.skip_if_binaries_missing(*KNOWN_BINARY_NAMES, check_all=False)
 @pytest.mark.requires_network
+@pytest.mark.skipif(
+    MISSING_SETUP_PY_FILE, reason="This test only work if setup.py is available"
+)
 class PipStateInstallationErrorTest(TestCase):
     @pytest.mark.slow_test
     def test_importable_installation_error(self):
diff --git a/tests/unit/utils/test_thin.py b/tests/unit/utils/test_thin.py
index f2369c70b0..3d9c3390b7 100644
--- a/tests/unit/utils/test_thin.py
+++ b/tests/unit/utils/test_thin.py
@@ -1437,6 +1437,9 @@ class SSHThinTestCase(TestCase):
                 assert [x for x in calls if f"{_file}" in x[-2]]
 
     @pytest.mark.slow_test
+    @pytest.mark.skip_if_binaries_missing(
+        "virtualenv", reason="Needs virtualenv binary"
+    )
     @pytest.mark.skip_on_windows(reason="salt-ssh does not deploy to/from windows")
     def test_thin_dir(self):
         """
-- 
2.47.0

openSUSE Build Service is sponsored by