Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit b6fc84c

Browse files
committed
avoid installing dependencies in runner when LocalStack isn't running in process
1 parent 7c60109 commit b6fc84c

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

localstack-core/localstack/testing/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22

3+
from localstack.config import is_env_true
34
from localstack.constants import DEFAULT_AWS_ACCOUNT_ID
45

56
# Credentials used in the test suite
@@ -19,3 +20,6 @@
1920
SECONDARY_TEST_AWS_SECRET_ACCESS_KEY = os.getenv("SECONDARY_TEST_AWS_SECRET_ACCESS_KEY") or "test2"
2021
SECONDARY_TEST_AWS_SESSION_TOKEN = os.getenv("SECONDARY_TEST_AWS_SESSION_TOKEN")
2122
SECONDARY_TEST_AWS_REGION_NAME = os.getenv("SECONDARY_TEST_AWS_REGION_NAME") or "ap-southeast-1"
23+
24+
TEST_SKIP_LOCALSTACK_START = is_env_true("TEST_SKIP_LOCALSTACK_START")
25+
TEST_FORCE_LOCALSTACK_START = is_env_true("TEST_FORCE_LOCALSTACK_START")

localstack-core/localstack/testing/pytest/in_memory_localstack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def pytest_configure(config):
2121
from _pytest.config.argparsing import Parser
2222
from _pytest.main import Session
2323

24+
import localstack.testing.config as test_config
2425
from localstack import config as localstack_config
25-
from localstack.config import is_env_true
2626
from localstack.constants import ENV_INTERNAL_TEST_RUN
2727

2828
LOG = logging.getLogger(__name__)
@@ -53,12 +53,12 @@ def pytest_runtestloop(session: Session):
5353

5454
from localstack.testing.aws.util import is_aws_cloud
5555

56-
if is_env_true("TEST_SKIP_LOCALSTACK_START"):
56+
if test_config.TEST_SKIP_LOCALSTACK_START:
5757
LOG.info("TEST_SKIP_LOCALSTACK_START is set, not starting localstack")
5858
return
5959

6060
if is_aws_cloud():
61-
if not is_env_true("TEST_FORCE_LOCALSTACK_START"):
61+
if not test_config.TEST_FORCE_LOCALSTACK_START:
6262
LOG.info("Test running against aws, not starting localstack")
6363
return
6464
LOG.info("TEST_FORCE_LOCALSTACK_START is set, a Localstack instance will be created.")

tests/aws/conftest.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from localstack import config as localstack_config
99
from localstack import constants
10+
from localstack.testing import config as test_config
1011
from localstack.testing.snapshots.transformer_utility import (
1112
SNAPSHOT_BASIC_TRANSFORMER,
1213
SNAPSHOT_BASIC_TRANSFORMER_NEW,
@@ -26,6 +27,26 @@ def pytest_configure(config: Config):
2627

2728

2829
def pytest_runtestloop(session):
30+
"""
31+
This pytest plugin allows us to pre-install external dependencies that are usually lazy-loaded by the services.
32+
This helps us surface download issues earlier.
33+
This is not needed if we are running the test against an external instance, as it installs the dependencies on the
34+
runner running the tests.
35+
"""
36+
if not session.items:
37+
return
38+
39+
if session.config.option.collectonly:
40+
return
41+
42+
if test_config.TEST_SKIP_LOCALSTACK_START:
43+
return
44+
45+
from localstack.testing.aws.util import is_aws_cloud
46+
47+
if is_aws_cloud() and not test_config.TEST_FORCE_LOCALSTACK_START:
48+
return
49+
2950
# second pytest lifecycle hook (before test runner starts)
3051
test_init_functions = set()
3152

@@ -56,12 +77,6 @@ def pytest_runtestloop(session):
5677

5778
test_init_functions.add(transcribe_install_async)
5879

59-
if not session.items:
60-
return
61-
62-
if session.config.option.collectonly:
63-
return
64-
6580
for fn in test_init_functions:
6681
fn()
6782

tests/aws/services/es/test_es.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
elasticsearch_package,
1212
opensearch_package,
1313
)
14+
from localstack.testing import config as test_config
15+
from localstack.testing.aws.util import is_aws_cloud
1416
from localstack.testing.pytest import markers
1517
from localstack.utils.common import safe_requests as requests
1618
from localstack.utils.common import short_uid, start_worker_thread
@@ -50,6 +52,10 @@ def run_install(*args):
5052

5153
@pytest.fixture(autouse=True)
5254
def elasticsearch():
55+
if is_aws_cloud() or test_config.TEST_SKIP_LOCALSTACK_START:
56+
# we don't install the dependencies if LocalStack is not running in process
57+
return
58+
5359
if not installed.is_set():
5460
install_async()
5561

tests/aws/services/opensearch/test_opensearch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
OPENSEARCH_PLUGIN_LIST,
4343
opensearch_package,
4444
)
45+
from localstack.testing import config as test_config
4546
from localstack.testing.aws.util import is_aws_cloud
4647
from localstack.testing.pytest import markers
4748
from localstack.utils.common import call_safe, poll_condition, retry, short_uid, start_worker_thread
@@ -81,6 +82,10 @@ def run_install(*args):
8182

8283
@pytest.fixture(autouse=True)
8384
def opensearch():
85+
if is_aws_cloud() or test_config.TEST_SKIP_LOCALSTACK_START:
86+
# we don't install the dependencies if LocalStack is not running in process
87+
return
88+
8489
if not installed.is_set():
8590
install_async()
8691

tests/aws/services/transcribe/test_transcribe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from localstack.packages.ffmpeg import ffmpeg_package
1515
from localstack.services.transcribe.packages import vosk_package
1616
from localstack.services.transcribe.provider import LANGUAGE_MODELS, TranscribeProvider
17+
from localstack.testing import config as test_config
1718
from localstack.testing.aws.util import is_aws_cloud
1819
from localstack.testing.pytest import markers
1920
from localstack.utils.files import new_tmp_file
@@ -97,6 +98,10 @@ def transcribe_snapshot_transformer(snapshot):
9798
class TestTranscribe:
9899
@pytest.fixture(scope="class", autouse=True)
99100
def pre_install_dependencies(self):
101+
if is_aws_cloud() or test_config.TEST_SKIP_LOCALSTACK_START:
102+
# we don't install the dependencies if LocalStack is not running in process
103+
return
104+
100105
if not ffmpeg_installed.is_set() or not vosk_installed.is_set():
101106
install_async()
102107

0 commit comments

Comments
 (0)