Replace the usage of @skipIf(...)

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2022-12-05 09:57:32 +00:00 committed by Pedro Algarvio
parent 80228e9001
commit f5b037af9c
14 changed files with 31 additions and 50 deletions

View file

@ -1,15 +1,12 @@
"""
Test the core grains
"""
import pytest
import salt.loader
import salt.utils.platform
from tests.support.case import ModuleCase
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf
if salt.utils.platform.is_windows():
try:
@ -18,17 +15,13 @@ if salt.utils.platform.is_windows():
pass
def _freebsd_or_openbsd():
return salt.utils.platform.is_freebsd() or salt.utils.platform.is_openbsd()
@pytest.mark.windows_whitelisted
class TestGrainsCore(ModuleCase):
"""
Test the core grains grains
"""
@skipIf(not _freebsd_or_openbsd(), "Only run on FreeBSD or OpenBSD")
@pytest.mark.skip_unless_on_platforms(freebsd=True, openbsd=True)
def test_freebsd_openbsd_mem_total(self):
"""
test grains['mem_total']
@ -38,7 +31,7 @@ class TestGrainsCore(ModuleCase):
self.run_function("grains.items")["mem_total"], int(physmem) // 1048576
)
@skipIf(not salt.utils.platform.is_openbsd(), "Only run on OpenBSD")
@pytest.mark.skip_unless_on_openbsd
def test_openbsd_swap_total(self):
"""
test grains['swap_total']

View file

@ -417,7 +417,7 @@ class CPModuleTest(ModuleCase):
with salt.utils.files.fopen(ret, "r") as cp_:
self.assertEqual(salt.utils.stringutils.to_unicode(cp_.read()), "foo")
@skipIf(not salt.utils.path.which("nginx"), "nginx not installed")
@pytest.mark.skip_if_binaries_missing("nginx")
@pytest.mark.slow_test
@pytest.mark.skip_if_not_root
def test_cache_remote_file(self):

View file

@ -4,10 +4,8 @@ Integration tests for Ruby Gem module
import pytest
import salt.utils.path
from salt.ext.tornado.httpclient import HTTPClient
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
def check_status():
@ -20,7 +18,7 @@ def check_status():
return False
@skipIf(not salt.utils.path.which("gem"), "Gem is not available")
@pytest.mark.skip_if_binaries_missing("gem")
@pytest.mark.windows_whitelisted
@pytest.mark.destructive_test
class GemModuleTest(ModuleCase):

View file

@ -2,6 +2,8 @@ import os
import subprocess
import time
import pytest
import salt.utils.path
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.support.case import ModuleCase
@ -12,7 +14,7 @@ from tests.support.unit import skipIf
@skipIf(
salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, "virtualenv not installed"
)
@skipIf(salt.utils.path.which("supervisorctl") is None, "supervisord not installed")
@pytest.mark.skip_if_binaries_missing("supervisorctl")
class SupervisordModuleTest(ModuleCase):
"""
Validates the supervisorctl functions.

View file

@ -1,7 +1,6 @@
import sys
import pytest
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
class SysctlModuleTest(ModuleCase):
@ -16,12 +15,12 @@ class SysctlModuleTest(ModuleCase):
self.assertIsInstance(ret, dict, "sysctl.show return wrong type")
self.assertGreater(len(ret), 10, "sysctl.show return few data")
@skipIf(not sys.platform.startswith("linux"), "Linux specific")
@pytest.mark.skip_unless_on_linux
def test_show_linux(self):
ret = self.run_function("sysctl.show")
self.assertIn("kernel.ostype", ret, "kernel.ostype absent")
@skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
@pytest.mark.skip_unless_on_freebsd
def test_show_freebsd(self):
ret = self.run_function("sysctl.show")
self.assertIn("vm.vmtotal", ret, "Multiline variable absent")
@ -31,13 +30,13 @@ class SysctlModuleTest(ModuleCase):
"Multiline value was parsed wrong",
)
@skipIf(not sys.platform.startswith("openbsd"), "OpenBSD specific")
@pytest.mark.skip_unless_on_openbsd
def test_show_openbsd(self):
ret = self.run_function("sysctl.show")
self.assertIn("kern.ostype", ret, "kern.ostype absent")
self.assertEqual(ret.get("kern.ostype"), "OpenBSD", "Incorrect kern.ostype")
@skipIf(not sys.platform.startswith("darwin"), "Darwin (macOS) specific")
@pytest.mark.skip_unless_on_darwin
def test_show_darwin(self):
ret = self.run_function("sysctl.show")
self.assertIn("kern.ostype", ret, "kern.ostype absent")

View file

@ -1,9 +1,10 @@
import sys
import pytest
from tests.support.case import ModuleCase
from tests.support.unit import skipIf
pytestmark = [
pytest.mark.skip_unless_on_freebsd,
]
class SysrcModuleTest(ModuleCase):
@ -13,7 +14,6 @@ class SysrcModuleTest(ModuleCase):
if not ret:
self.skipTest("sysrc not found")
@skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
def test_show(self):
ret = self.run_function("sysrc.get")
self.assertIsInstance(
@ -23,7 +23,6 @@ class SysrcModuleTest(ModuleCase):
"/etc/rc.conf", ret, "sysrc.get should have an rc.conf key in it."
)
@skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
@pytest.mark.destructive_test
def test_set(self):
ret = self.run_function("sysrc.set", ["test_var", "1"])
@ -41,7 +40,6 @@ class SysrcModuleTest(ModuleCase):
ret = self.run_function("sysrc.remove", ["test_var"])
self.assertEqual("test_var removed", ret)
@skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
@pytest.mark.destructive_test
def test_set_bool(self):
ret = self.run_function("sysrc.set", ["test_var", True])

View file

@ -111,6 +111,7 @@ HAS_VIRTUALENV = bool(salt.utils.path.which_bin(VIRTUALENV_NAMES))
pytestmark = [
SKIP_INITIAL_PHOTONOS_FAILURES,
pytest.mark.skip_on_platforms(windows=True, darwin=True),
]
@ -120,10 +121,6 @@ def _rand_key_name(length):
)
def _windows_or_mac():
return salt.utils.platform.is_windows() or salt.utils.platform.is_darwin()
def _centos_stream_9():
(osname, osrelease, oscodename) = (
x.strip('"').strip("'") for x in linux_distribution()
@ -696,7 +693,6 @@ class GitPythonMixin:
self.assertEqual(excinfo.exception.strerror, "Failed to load git_pillar")
@skipIf(_windows_or_mac(), "minion is windows or mac")
@skipIf(not HAS_GITPYTHON, "GitPython >= {} required".format(GITPYTHON_MINVER))
@skipIf(not HAS_SSHD, "sshd not present")
@pytest.mark.usefixtures("ssh_pillar_tests_prep")
@ -713,7 +709,6 @@ class TestGitPythonSSH(GitPillarSSHTestBase, GitPythonMixin):
passphrase = PASSWORD
@skipIf(_windows_or_mac(), "minion is windows or mac")
@skipIf(not HAS_GITPYTHON, "GitPython >= {} required".format(GITPYTHON_MINVER))
@skipIf(not HAS_NGINX, "nginx not present")
@skipIf(not HAS_VIRTUALENV, "virtualenv not present")
@ -725,7 +720,6 @@ class TestGitPythonHTTP(GitPillarHTTPTestBase, GitPythonMixin):
"""
@skipIf(_windows_or_mac(), "minion is windows or mac")
@skipIf(not HAS_GITPYTHON, "GitPython >= {} required".format(GITPYTHON_MINVER))
@skipIf(not HAS_NGINX, "nginx not present")
@skipIf(not HAS_VIRTUALENV, "virtualenv not present")
@ -741,7 +735,6 @@ class TestGitPythonAuthenticatedHTTP(TestGitPythonHTTP, GitPythonMixin):
@skipIf(salt.utils.platform.is_aarch64(), "Test is broken on aarch64")
@skipIf(_windows_or_mac(), "minion is windows or mac")
@skipIf(_centos_stream_9(), "CentOS Stream 9 has RSA keys disabled by default")
@skipIf(
not HAS_PYGIT2,
@ -2357,7 +2350,6 @@ class TestPygit2SSH(GitPillarSSHTestBase):
self.assertEqual(excinfo.exception.strerror, "Failed to load git_pillar")
@skipIf(_windows_or_mac(), "minion is windows or mac")
@skipIf(
not HAS_PYGIT2,
"pygit2 >= {} and libgit2 >= {} required".format(PYGIT2_MINVER, LIBGIT2_MINVER),
@ -2922,7 +2914,6 @@ class TestPygit2HTTP(GitPillarHTTPTestBase):
self.assertEqual(excinfo.exception.strerror, "Failed to load git_pillar")
@skipIf(_windows_or_mac(), "minion is windows or mac")
@skipIf(
not HAS_PYGIT2,
"pygit2 >= {} and libgit2 >= {} required".format(PYGIT2_MINVER, LIBGIT2_MINVER),

View file

@ -10,7 +10,6 @@ import pytest
import salt.utils.files
import salt.utils.path
from tests.support.case import ModuleCase, SPMCase
from tests.support.unit import skipIf
@pytest.mark.windows_whitelisted
@ -35,7 +34,7 @@ class SPMBuildTest(SPMCase, ModuleCase):
# Make sure formula path dir is created
self.assertTrue(os.path.isdir(self.config["formula_path"]))
@skipIf(salt.utils.path.which("fallocate") is None, "fallocate not installed")
@pytest.mark.skip_if_binaries_missing("fallocate")
@pytest.mark.slow_test
def test_spm_build_big_file(self):
"""

View file

@ -8,10 +8,9 @@ import salt.utils.json
import salt.utils.path
from tests.support.case import ModuleCase
from tests.support.mixins import SaltReturnAssertsMixin
from tests.support.unit import skipIf
@skipIf(salt.utils.path.which("bower") is None, "bower not installed")
@pytest.mark.skip_if_binaries_missing("bower")
class BowerStateTest(ModuleCase, SaltReturnAssertsMixin):
@pytest.mark.destructive_test
@pytest.mark.slow_test

View file

@ -8,6 +8,8 @@ import os
import subprocess
import time
import pytest
import salt.utils.path
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.support.case import ModuleCase
@ -19,7 +21,7 @@ from tests.support.unit import skipIf
@skipIf(
salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, "virtualenv not installed"
)
@skipIf(salt.utils.path.which("supervisorctl") is None, "supervisord not installed")
@pytest.mark.skip_if_binaries_missing("supervisorctl")
class SupervisordTest(ModuleCase, SaltReturnAssertsMixin):
"""
Validate the supervisord states.

View file

@ -7,15 +7,15 @@ the KitchenTestCase.
import os
import salt.utils.path
import setup
from salt.modules import cmdmod as cmd
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase
import pytest
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
@skipIf(not salt.utils.path.which("bundle"), "Bundler is not installed")
@pytest.mark.skip_if_binaries_missing("bundle")
class KitchenTestCase(TestCase):
"""
Test kitchen environments

View file

@ -301,7 +301,7 @@ def test_resize2fs():
@pytest.mark.skip_on_windows(reason="Skip on Windows")
@skipIf(not salt.utils.path.which("mkfs"), "mkfs not found")
@pytest.mark.skip_if_binaries_missing("mkfs")
def test_format_():
"""
unit tests for disk.format_
@ -314,7 +314,7 @@ def test_format_():
@pytest.mark.skip_on_windows(reason="Skip on Windows")
@skipIf(not salt.utils.path.which("mkfs"), "mkfs not found")
@pytest.mark.skip_if_binaries_missing("mkfs")
def test_format__fat():
"""
unit tests for disk.format_ with FAT parameter

View file

@ -6,7 +6,6 @@ import pytest
import salt.output.highstate as highstate
import salt.utils.stringutils
from tests.support.mock import patch
from tests.support.unit import skipIf
log = logging.getLogger(__name__)

View file

@ -8,14 +8,15 @@ import copy
import os
import textwrap
import pytest
import salt.modules.opkg as opkg
import salt.utils.platform
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, mock_open, patch
from tests.support.unit import TestCase, skipIf
from tests.support.unit import TestCase
@skipIf(not salt.utils.platform.is_linux(), "Must be on Linux!")
@pytest.mark.skip_unless_on_linux
class OpkgTestCase(TestCase, LoaderModuleMockMixin):
"""
Test cases for salt.modules.opkg