mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
We no longer need the distinction between running under PyTest or not
This commit is contained in:
parent
bf83bc5e26
commit
87019146af
12 changed files with 23 additions and 130 deletions
|
@ -733,7 +733,7 @@ def _pytest(session, coverage, cmd_args):
|
|||
# Create required artifacts directories
|
||||
_create_ci_directories()
|
||||
|
||||
env = {"PYTEST_SESSION": "1", "CI_RUN": "1" if CI_RUN else "0"}
|
||||
env = {"CI_RUN": "1" if CI_RUN else "0"}
|
||||
if IS_DARWIN:
|
||||
# Don't nuke our multiprocessing efforts objc!
|
||||
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
|
||||
|
|
|
@ -246,9 +246,6 @@ def pytest_configure(config):
|
|||
"markers",
|
||||
"slow_test: Mark test as being slow. These tests are skipped by default unless `--run-slow` is passed",
|
||||
)
|
||||
# Make sure the test suite "knows" this is a pytest test run
|
||||
RUNTIME_VARS.PYTEST_SESSION = True
|
||||
|
||||
# "Flag" the slowTest decorator if we're skipping slow tests or not
|
||||
os.environ["SLOW_TESTS"] = str(config.getoption("--run-slow"))
|
||||
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
# -tests/integration/daemons/test_masterapi.py:71*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
|
@ -12,8 +8,6 @@ from tests.support.case import ShellCase
|
|||
from tests.support.helpers import slowTest
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
||||
|
||||
class AutosignGrainsTest(ShellCase):
|
||||
"""
|
||||
|
@ -25,12 +19,7 @@ class AutosignGrainsTest(ShellCase):
|
|||
self.autosign_file_permissions = (
|
||||
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR
|
||||
)
|
||||
if RUNTIME_VARS.PYTEST_SESSION:
|
||||
self.autosign_file_path = os.path.join(RUNTIME_VARS.TMP, "autosign_file")
|
||||
else:
|
||||
self.autosign_file_path = os.path.join(
|
||||
RUNTIME_VARS.TMP, "rootdir", "autosign_file"
|
||||
)
|
||||
self.autosign_file_path = os.path.join(RUNTIME_VARS.TMP, "autosign_file")
|
||||
shutil.copyfile(
|
||||
os.path.join(RUNTIME_VARS.FILES, "autosign_grains", "autosign_file"),
|
||||
self.autosign_file_path,
|
||||
|
|
|
@ -11,12 +11,7 @@ import salt.utils.platform
|
|||
import salt.utils.pycrypto
|
||||
from salt.exceptions import EauthAuthenticationError
|
||||
from tests.support.case import ModuleCase, SSHCase
|
||||
from tests.support.helpers import (
|
||||
SKIP_IF_NOT_RUNNING_PYTEST,
|
||||
SaveRequestsPostHandler,
|
||||
Webserver,
|
||||
slowTest,
|
||||
)
|
||||
from tests.support.helpers import SaveRequestsPostHandler, Webserver, slowTest
|
||||
from tests.support.mixins import AdaptedConfigurationTestCaseMixin
|
||||
from tests.support.mock import patch
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
@ -163,7 +158,6 @@ class NetapiClientTest(TestCase):
|
|||
ret = self.netapi.run(low)
|
||||
|
||||
|
||||
@SKIP_IF_NOT_RUNNING_PYTEST
|
||||
@pytest.mark.requires_sshd_server
|
||||
class NetapiSSHClientTest(SSHCase):
|
||||
eauth_creds = {
|
||||
|
|
|
@ -11,18 +11,12 @@ import salt.utils.files
|
|||
import salt.utils.path
|
||||
import yaml
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.helpers import (
|
||||
SKIP_IF_NOT_RUNNING_PYTEST,
|
||||
destructiveTest,
|
||||
flaky,
|
||||
requires_system_grains,
|
||||
)
|
||||
from tests.support.helpers import destructiveTest, flaky, requires_system_grains
|
||||
from tests.support.mixins import SaltReturnAssertsMixin
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import SkipTest, skipIf
|
||||
|
||||
|
||||
@SKIP_IF_NOT_RUNNING_PYTEST
|
||||
@destructiveTest
|
||||
@pytest.mark.requires_sshd_server
|
||||
@skipIf(
|
||||
|
|
|
@ -27,7 +27,7 @@ import pytest
|
|||
import salt.utils.files
|
||||
from saltfactories.utils.processes import terminate_process
|
||||
from tests.support.cli_scripts import ScriptPathMixin
|
||||
from tests.support.helpers import SKIP_IF_NOT_RUNNING_PYTEST, RedirectStdStreams
|
||||
from tests.support.helpers import RedirectStdStreams
|
||||
from tests.support.mixins import ( # pylint: disable=unused-import
|
||||
AdaptedConfigurationTestCaseMixin,
|
||||
SaltClientTestCaseMixin,
|
||||
|
@ -752,18 +752,13 @@ class ModuleCase(TestCase, SaltClientTestCaseMixin):
|
|||
)
|
||||
orig = client.cmd(minion_tgt, function, arg, timeout=timeout, kwarg=kwargs)
|
||||
|
||||
if RUNTIME_VARS.PYTEST_SESSION:
|
||||
fail_or_skip_func = self.fail
|
||||
else:
|
||||
fail_or_skip_func = self.skipTest
|
||||
|
||||
if minion_tgt not in orig:
|
||||
fail_or_skip_func(
|
||||
self.fail(
|
||||
"WARNING(SHOULD NOT HAPPEN #1935): Failed to get a reply "
|
||||
"from the minion '{}'. Command output: {}".format(minion_tgt, orig)
|
||||
)
|
||||
elif orig[minion_tgt] is None and function not in known_to_return_none:
|
||||
fail_or_skip_func(
|
||||
self.fail(
|
||||
"WARNING(SHOULD NOT HAPPEN #1935): Failed to get '{}' from "
|
||||
"the minion '{}'. Command output: {}".format(function, minion_tgt, orig)
|
||||
)
|
||||
|
@ -829,19 +824,14 @@ class SyndicCase(TestCase, SaltClientTestCaseMixin):
|
|||
behavior of the raw function call
|
||||
"""
|
||||
orig = self.client.cmd("minion", function, arg, timeout=timeout)
|
||||
if RUNTIME_VARS.PYTEST_SESSION:
|
||||
fail_or_skip_func = self.fail
|
||||
else:
|
||||
fail_or_skip_func = self.skipTest
|
||||
if "minion" not in orig:
|
||||
fail_or_skip_func(
|
||||
self.fail(
|
||||
"WARNING(SHOULD NOT HAPPEN #1935): Failed to get a reply "
|
||||
"from the minion. Command output: {}".format(orig)
|
||||
)
|
||||
return orig["minion"]
|
||||
|
||||
|
||||
@SKIP_IF_NOT_RUNNING_PYTEST
|
||||
@pytest.mark.requires_sshd_server
|
||||
class SSHCase(ShellCase):
|
||||
"""
|
||||
|
|
|
@ -22,11 +22,7 @@ from saltfactories.factories.base import DaemonFactory
|
|||
from saltfactories.factories.daemons.sshd import SshdDaemonFactory as _SshdDaemonFactory
|
||||
from saltfactories.utils.ports import get_unused_localhost_port
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.helpers import (
|
||||
SKIP_IF_NOT_RUNNING_PYTEST,
|
||||
patched_environ,
|
||||
requires_system_grains,
|
||||
)
|
||||
from tests.support.helpers import patched_environ, requires_system_grains
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import patch
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
@ -390,7 +386,6 @@ def webserver_pillar_tests_prep_authenticated(request, webserver_pillar_tests_pr
|
|||
request.cls.ext_opts["password"] = request.cls.password
|
||||
|
||||
|
||||
@SKIP_IF_NOT_RUNNING_PYTEST
|
||||
class GitTestBase(ModuleCase):
|
||||
"""
|
||||
Base class for all gitfs/git_pillar tests.
|
||||
|
|
|
@ -45,7 +45,7 @@ from saltfactories.utils.processes import ProcessResult
|
|||
from tests.support.mock import patch
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.sminion import create_sminion
|
||||
from tests.support.unit import SkipTest, _id, skip, skipIf
|
||||
from tests.support.unit import SkipTest, _id, skip
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -59,9 +59,6 @@ PRE_PYTEST_SKIP_REASON = (
|
|||
PRE_PYTEST_SKIP = pytest.mark.skipif(
|
||||
PRE_PYTEST_SKIP_OR_NOT, reason=PRE_PYTEST_SKIP_REASON
|
||||
)
|
||||
SKIP_IF_NOT_RUNNING_PYTEST = skipIf(
|
||||
RUNTIME_VARS.PYTEST_SESSION is False, "These tests now require running under PyTest"
|
||||
)
|
||||
ON_PY35 = sys.version_info < (3, 6)
|
||||
|
||||
|
||||
|
@ -104,11 +101,7 @@ def destructiveTest(caller):
|
|||
def test_create_user(self):
|
||||
pass
|
||||
"""
|
||||
# Late import
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
if RUNTIME_VARS.PYTEST_SESSION:
|
||||
setattr(caller, "__destructive_test__", True)
|
||||
setattr(caller, "__destructive_test__", True)
|
||||
|
||||
if os.environ.get("DESTRUCTIVE_TESTS", "False").lower() == "false":
|
||||
reason = "Destructive tests are disabled"
|
||||
|
@ -140,11 +133,7 @@ def expensiveTest(caller):
|
|||
def test_create_user(self):
|
||||
pass
|
||||
"""
|
||||
# Late import
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
if RUNTIME_VARS.PYTEST_SESSION:
|
||||
setattr(caller, "__expensive_test__", True)
|
||||
setattr(caller, "__expensive_test__", True)
|
||||
|
||||
if os.environ.get("EXPENSIVE_TESTS", "False").lower() == "false":
|
||||
reason = "Expensive tests are disabled"
|
||||
|
@ -172,26 +161,7 @@ def slowTest(caller):
|
|||
def test_that_takes_much_time(self):
|
||||
pass
|
||||
"""
|
||||
# Late import
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
if RUNTIME_VARS.PYTEST_SESSION:
|
||||
setattr(caller, "__slow_test__", True)
|
||||
return caller
|
||||
|
||||
if os.environ.get("SLOW_TESTS", "False").lower() == "false":
|
||||
reason = "Slow tests are disabled"
|
||||
|
||||
if not isinstance(caller, type):
|
||||
|
||||
@functools.wraps(caller)
|
||||
def skip_wrapper(*args, **kwargs):
|
||||
raise SkipTest(reason)
|
||||
|
||||
caller = skip_wrapper
|
||||
|
||||
caller.__unittest_skip__ = True
|
||||
caller.__unittest_skip_why__ = reason
|
||||
setattr(caller, "__slow_test__", True)
|
||||
return caller
|
||||
|
||||
|
||||
|
@ -1230,11 +1200,7 @@ def skip_if_binaries_missing(*binaries, **kwargs):
|
|||
|
||||
|
||||
def skip_if_not_root(func):
|
||||
# Late import
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
if RUNTIME_VARS.PYTEST_SESSION:
|
||||
setattr(func, "__skip_if_not_root__", True)
|
||||
setattr(func, "__skip_if_not_root__", True)
|
||||
|
||||
if not sys.platform.startswith("win"):
|
||||
if os.getuid() != 0:
|
||||
|
|
|
@ -27,18 +27,6 @@ from tests.support.sminion import create_sminion
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
if not RUNTIME_VARS.PYTEST_SESSION:
|
||||
# XXX: Remove this try/except once we fully switch to pytest
|
||||
|
||||
class FakePyTestHelpersNamespace:
|
||||
__slots__ = ()
|
||||
|
||||
def register(self, func):
|
||||
return func
|
||||
|
||||
# Patch pytest so it all works under runtests.py
|
||||
pytest.helpers = FakePyTestHelpersNamespace()
|
||||
|
||||
|
||||
@pytest.helpers.register
|
||||
@contextmanager
|
||||
|
|
|
@ -206,6 +206,5 @@ RUNTIME_VARS = RuntimeVars(
|
|||
BASE_FILES=paths.BASE_FILES,
|
||||
PROD_FILES=paths.PROD_FILES,
|
||||
TESTS_DIR=paths.TESTS_DIR,
|
||||
PYTEST_SESSION="PYTEST_SESSION" in os.environ,
|
||||
)
|
||||
# <---- Tests Runtime Variables --------------------------------------------------------------------------------------
|
||||
|
|
|
@ -790,18 +790,10 @@ class ConfigTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
|||
self.assertEqual(syndic_opts["id"], "syndic")
|
||||
self.assertEqual(syndic_opts["pki_dir"], os.path.join(root_dir, "pki"))
|
||||
# the rest is configured master side
|
||||
if RUNTIME_VARS.PYTEST_SESSION is False:
|
||||
# Pytest assigns ports dynamically
|
||||
self.assertEqual(syndic_opts["master_port"], 54506)
|
||||
self.assertEqual(syndic_opts["master"], "localhost")
|
||||
self.assertEqual(
|
||||
syndic_opts["sock_dir"], os.path.join(root_dir, "syndic_sock")
|
||||
)
|
||||
else:
|
||||
self.assertEqual(syndic_opts["master"], "127.0.0.1")
|
||||
self.assertEqual(
|
||||
syndic_opts["sock_dir"], os.path.join(root_dir, "run", "minion")
|
||||
)
|
||||
self.assertEqual(syndic_opts["master"], "127.0.0.1")
|
||||
self.assertEqual(
|
||||
syndic_opts["sock_dir"], os.path.join(root_dir, "run", "minion")
|
||||
)
|
||||
self.assertEqual(syndic_opts["cachedir"], os.path.join(root_dir, "cache"))
|
||||
self.assertEqual(
|
||||
syndic_opts["log_file"], os.path.join(root_dir, "logs", "syndic.log")
|
||||
|
|
|
@ -21,7 +21,6 @@ from salt.exceptions import (
|
|||
)
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, PropertyMock, call, patch
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import TestCase, skipIf
|
||||
|
||||
try:
|
||||
|
@ -2906,9 +2905,7 @@ class CreateDvsTestCase(TestCase):
|
|||
self.mock_wait_for_task.assert_called_once_with(
|
||||
self.mock_task,
|
||||
"fake_dvs",
|
||||
"<class '{}unit.utils.test_vmware.FakeTaskClass'>".format(
|
||||
"tests." if RUNTIME_VARS.PYTEST_SESSION else ""
|
||||
),
|
||||
"<class 'tests.unit.utils.test_vmware.FakeTaskClass'>",
|
||||
)
|
||||
|
||||
|
||||
|
@ -2989,9 +2986,7 @@ class UpdateDvsTestCase(TestCase):
|
|||
self.mock_wait_for_task.assert_called_once_with(
|
||||
self.mock_task,
|
||||
"fake_dvs",
|
||||
"<class '{}unit.utils.test_vmware.FakeTaskClass'>".format(
|
||||
"tests." if RUNTIME_VARS.PYTEST_SESSION else ""
|
||||
),
|
||||
"<class 'tests.unit.utils.test_vmware.FakeTaskClass'>",
|
||||
)
|
||||
|
||||
|
||||
|
@ -3346,9 +3341,7 @@ class CreateDvportgroupTestCase(TestCase):
|
|||
self.mock_wait_for_task.assert_called_once_with(
|
||||
self.mock_task,
|
||||
"fake_dvs",
|
||||
"<class '{}unit.utils.test_vmware.FakeTaskClass'>".format(
|
||||
"tests." if RUNTIME_VARS.PYTEST_SESSION else ""
|
||||
),
|
||||
"<class 'tests.unit.utils.test_vmware.FakeTaskClass'>",
|
||||
)
|
||||
|
||||
|
||||
|
@ -3424,9 +3417,7 @@ class UpdateDvportgroupTestCase(TestCase):
|
|||
self.mock_wait_for_task.assert_called_once_with(
|
||||
self.mock_task,
|
||||
"fake_pg",
|
||||
"<class '{}unit.utils.test_vmware.FakeTaskClass'>".format(
|
||||
"tests." if RUNTIME_VARS.PYTEST_SESSION else ""
|
||||
),
|
||||
"<class 'tests.unit.utils.test_vmware.FakeTaskClass'>",
|
||||
)
|
||||
|
||||
|
||||
|
@ -3499,9 +3490,7 @@ class RemoveDvportgroupTestCase(TestCase):
|
|||
self.mock_wait_for_task.assert_called_once_with(
|
||||
self.mock_task,
|
||||
"fake_pg",
|
||||
"<class '{}unit.utils.test_vmware.FakeTaskClass'>".format(
|
||||
"tests." if RUNTIME_VARS.PYTEST_SESSION else ""
|
||||
),
|
||||
"<class 'tests.unit.utils.test_vmware.FakeTaskClass'>",
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue