Skip to content
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

Clean up import side effects in tests #6241

Merged
merged 9 commits into from
Sep 16, 2024
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Added
* Continue introducing `pants <https://www.pantsbuild.org/docs>`_ to improve DX (Developer Experience)
working on StackStorm, improve our security posture, and improve CI reliability thanks in part
to pants' use of PEX lockfiles. This is not a user-facing addition.
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241
Contributed by @cognifloyd
* Build of ST2 EL9 packages #6153
Contributed by @amanda11
Expand Down
7 changes: 2 additions & 5 deletions st2actions/tests/unit/policies/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
from __future__ import absolute_import
import mock

from st2tests import config as test_config

test_config.parse_args()
# This import must be early for import-time side-effects.
from st2tests.base import CleanDbTestCase, DbTestCase

import st2common
from st2common.bootstrap.policiesregistrar import register_policy_types
Expand All @@ -28,8 +27,6 @@
from st2common.services import action as action_service
from st2common.services import policies as policy_service
from st2common.bootstrap import runnersregistrar as runners_registrar
from st2tests.base import DbTestCase
from st2tests.base import CleanDbTestCase
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader

Expand Down
7 changes: 2 additions & 5 deletions st2actions/tests/unit/policies/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from mock import call
from six.moves import range

# This import must be early for import-time side-effects.
# Importing st2actions.scheduler relies on config being parsed :/
import st2tests.config as tests_config

tests_config.parse_args()
from st2tests import DbTestCase, EventletTestCase, ExecutionDbTestCase

import st2common
from st2actions.scheduler import handler as scheduling_queue
Expand All @@ -38,8 +37,6 @@
from st2common.transport.liveaction import LiveActionPublisher
from st2common.transport.publishers import CUDPublisher
from st2common.bootstrap import runnersregistrar as runners_registrar
from st2tests import DbTestCase, EventletTestCase
from st2tests import ExecutionDbTestCase
import st2tests.config as tests_config
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader
Expand Down
6 changes: 2 additions & 4 deletions st2actions/tests/unit/policies/test_concurrency_by_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
import mock
from mock import call

# This import must be early for import-time side-effects.
# Importing st2actions.scheduler relies on config being parsed :/
import st2tests.config as tests_config

tests_config.parse_args()
from st2tests import ExecutionDbTestCase, EventletTestCase

import st2common
from st2actions.scheduler import handler as scheduling_queue
Expand All @@ -36,7 +35,6 @@
from st2common.transport.liveaction import LiveActionPublisher
from st2common.transport.publishers import CUDPublisher
from st2common.bootstrap import runnersregistrar as runners_registrar
from st2tests import ExecutionDbTestCase, EventletTestCase
import st2tests.config as tests_config
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader
Expand Down
9 changes: 6 additions & 3 deletions st2actions/tests/unit/test_action_runner_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
from st2common.transport.consumers import ActionsQueueConsumer
from st2common.models.db.liveaction import LiveActionDB

from st2tests import config as test_config

test_config.parse_args()
from st2tests import config as tests_config

__all__ = ["ActionsQueueConsumerTestCase"]


class ActionsQueueConsumerTestCase(TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()

def test_process_right_dispatcher_is_used(self):
handler = Mock()
handler.message_type = LiveActionDB
Expand Down
7 changes: 2 additions & 5 deletions st2actions/tests/unit/test_execution_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

from oslo_config import cfg

# XXX: actionsensor import depends on config being setup.
import st2tests.config as tests_config

tests_config.parse_args()
# This import must be early for import-time side-effects.
from st2tests import ExecutionDbTestCase

from st2common.constants import action as action_constants
from st2common.models.api.action import ActionAPI
Expand All @@ -36,7 +34,6 @@
from st2common.services import trace as trace_service
from st2common.transport.liveaction import LiveActionPublisher
from st2common.transport.publishers import CUDPublisher
from st2tests import ExecutionDbTestCase
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
from st2tests.fixturesloader import FixturesLoader
from st2tests.mocks.execution import MockExecutionPublisher
Expand Down
7 changes: 2 additions & 5 deletions st2actions/tests/unit/test_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

import mock

# XXX: actionsensor import depends on config being setup.
import st2tests.config as tests_config

tests_config.parse_args()
# This import must be early for import-time side-effects.
from st2tests import ExecutionDbTestCase

import st2common.bootstrap.runnersregistrar as runners_registrar
from st2common.constants import action as action_constants
Expand All @@ -46,7 +44,6 @@
from local_runner.local_shell_command_runner import LocalShellCommandRunner

from st2tests.fixtures.packs import executions as fixture
from st2tests import ExecutionDbTestCase
from st2tests.mocks.liveaction import MockLiveActionPublisher


Expand Down
6 changes: 2 additions & 4 deletions st2actions/tests/unit/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import bson
import mock

import st2tests.config as tests_config

tests_config.parse_args()
# This import must be early for import-time side-effects.
from st2tests.base import CleanDbTestCase

from st2actions.notifier.notifier import Notifier
from st2common.constants.action import LIVEACTION_COMPLETED_STATES
Expand All @@ -40,7 +39,6 @@
from st2common.models.system.common import ResourceReference
from st2common.util import date as date_utils
from st2common.util import isotime
from st2tests.base import CleanDbTestCase

ACTION_TRIGGER_TYPE = INTERNAL_TRIGGER_TYPES["action"][0]
NOTIFY_TRIGGER_TYPE = INTERNAL_TRIGGER_TYPES["action"][1]
Expand Down
5 changes: 1 addition & 4 deletions st2actions/tests/unit/test_output_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
from python_runner import python_runner
from orquesta_runner import orquesta_runner

# This import must be early for import-time side-effects.
import st2tests

import st2tests.config as tests_config

tests_config.parse_args()

from st2common.bootstrap import actionsregistrar
from st2common.bootstrap import runnersregistrar
from st2common.constants import action as ac_const
Expand Down
7 changes: 5 additions & 2 deletions st2actions/tests/unit/test_parallel_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from st2common.runners.paramiko_ssh import SSHCommandTimeoutError
import st2tests.config as tests_config

tests_config.parse_args()

MOCK_STDERR_SUDO_PASSWORD_ERROR = """
[sudo] password for bar: Sorry, try again.\n
[sudo] password for bar:' Sorry, try again.\n
Expand All @@ -36,6 +34,11 @@


class ParallelSSHTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()

@patch("paramiko.SSHClient", Mock)
@patch.object(
ParamikoSSHClient,
Expand Down
7 changes: 5 additions & 2 deletions st2actions/tests/unit/test_paramiko_remote_script_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# before importing remote_script_runner classes.
import st2tests.config as tests_config

tests_config.parse_args()

from st2common.util import jsonify
from st2common.models.db.action import ActionDB
from st2common.runners.parallel_ssh import ParallelSSHClient
Expand All @@ -48,6 +46,11 @@


class ParamikoScriptRunnerTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()

@patch("st2common.runners.parallel_ssh.ParallelSSHClient", Mock)
@patch.object(jsonify, "json_loads", MagicMock(return_value={}))
@patch.object(ParallelSSHClient, "run", MagicMock(return_value={}))
Expand Down
7 changes: 5 additions & 2 deletions st2actions/tests/unit/test_paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
from st2tests.fixturesloader import get_resources_base_path
import st2tests.config as tests_config

tests_config.parse_args()

__all__ = ["ParamikoSSHClientTestCase"]


class ParamikoSSHClientTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()

@patch("paramiko.SSHClient", Mock)
def setUp(self):
"""
Expand Down
7 changes: 5 additions & 2 deletions st2actions/tests/unit/test_paramiko_ssh_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@
import st2tests.config as tests_config
from st2tests.fixturesloader import get_resources_base_path

tests_config.parse_args()


class Runner(BaseParallelSSHRunner):
def run(self):
pass


class ParamikoSSHRunnerTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()

@mock.patch("st2common.runners.paramiko_ssh_runner.ParallelSSHClient")
def test_pre_run(self, mock_client):
# Test case which verifies that ParamikoSSHClient is instantiated with the correct arguments
Expand Down
8 changes: 3 additions & 5 deletions st2actions/tests/unit/test_queue_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@

from __future__ import absolute_import

import st2tests.config as tests_config

tests_config.parse_args()

import mock
from kombu.message import Message

# This import must be early for import-time side-effects.
from st2tests.base import ExecutionDbTestCase

from st2actions import worker
from st2actions.scheduler import entrypoint as scheduling
from st2actions.scheduler import handler as scheduling_queue
Expand All @@ -35,7 +34,6 @@
from st2common.transport.publishers import PoolPublisher
from st2common.util import action_db as action_utils
from st2common.util import date as date_utils
from st2tests.base import ExecutionDbTestCase
from st2tests.fixtures.packs.core.fixture import PACK_PATH as CORE_PACK_PATH


Expand Down
14 changes: 8 additions & 6 deletions st2actions/tests/unit/test_remote_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# XXX: FabricRunner import depends on config being setup.
from __future__ import absolute_import
import st2tests.config as tests_config

tests_config.parse_args()

from unittest import TestCase

# This import must be early for import-time side-effects.
import st2tests.config as tests_config

from st2common.models.system.action import RemoteScriptAction


class RemoteScriptActionTestCase(TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()

def test_parameter_formatting(self):
# Only named args
named_args = {
Expand Down
7 changes: 3 additions & 4 deletions st2actions/tests/unit/test_runner_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from oslo_config import cfg

# This import must be early for import-time side-effects.
from st2tests.base import DbTestCase

from st2common.constants import action as action_constants
from st2common.runners.base import get_runner
from st2common.exceptions.actionrunner import (
Expand All @@ -35,10 +38,6 @@
from st2common.util import date as date_utils
from st2common.transport.publishers import PoolPublisher

from st2tests.base import DbTestCase
import st2tests.config as tests_config

tests_config.parse_args()
from st2tests.fixtures.generic.fixture import PACK_NAME as FIXTURES_PACK
from st2tests.fixturesloader import FixturesLoader

Expand Down
4 changes: 0 additions & 4 deletions st2actions/tests/unit/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
import mock
import eventlet

from st2tests import config as test_config

test_config.parse_args()

import st2common
from st2tests import ExecutionDbTestCase
from st2tests.fixtures.generic.fixture import PACK_NAME as PACK
Expand Down
4 changes: 0 additions & 4 deletions st2actions/tests/unit/test_scheduler_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
import eventlet
import mock

from st2tests import config as test_config

test_config.parse_args()

from st2actions.cmd.scheduler import _run_scheduler
from st2actions.scheduler.handler import ActionExecutionSchedulingQueueHandler
from st2actions.scheduler.entrypoint import SchedulerEntrypoint
Expand Down
8 changes: 3 additions & 5 deletions st2actions/tests/unit/test_scheduler_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# This import must be first for import-time side-effects.
from st2tests.base import CleanDbTestCase

import eventlet
import mock
import pymongo
import uuid

from st2tests import config as test_config

test_config.parse_args()

from st2actions.scheduler import handler
from st2common.models.db import execution_queue as ex_q_db
from st2common.persistence import execution_queue as ex_q_db_access
from st2tests.base import CleanDbTestCase


__all__ = ["SchedulerHandlerRetryTestCase"]
Expand Down
Loading
Loading