Skip to content

Defer CDK imports in infra provisioning #12591

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

Merged
merged 2 commits into from
May 7, 2025
Merged

Conversation

dfangl
Copy link
Member

@dfangl dfangl commented May 7, 2025

Motivation

Currently, we import the localstack.testing.scenario.provisioning module on every pytest run, which in turns imports the aws_cdk python bindings.

This leads to a heavy increase in startup time, especially when debugging (tested in Pycharm).

By deferring the import to the first fixture usage, instead of on all imports, that increased delay will only happen for tests actually requesting the fixture, instead of all tests.

For unrelated tests, this can reduce the start time of the test (on my system):

  • When debugging, from 46 to 7 seconds
  • Without debugging, from 7 to 1 seconds

CI runtime should only marginally be affected, only if test selection selects tests without a single usage of the infra provisioner.

I also fixed the mypy precommit errors happening on my system, by ignoring the plux import completely, instead of just ignoring import-untyped errors.

Changes

  • Defer infra provisioner imports to actual fixture usages
  • Ignore plux type errors completely to prevent mypy precommit errors

@dfangl dfangl requested a review from alexrashed as a code owner May 7, 2025 13:20
@dfangl dfangl added the semver: patch Non-breaking changes which can be included in patch releases label May 7, 2025
@dfangl dfangl self-assigned this May 7, 2025
@alexrashed alexrashed requested a review from bblommers May 7, 2025 13:26
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Thanks a lot for jumping on this! Absolutely great to fix this issue, speeding up our own development cycles / improving our own DevX! 💯 🦸🏽
I added @bblommers as reviewer to quickly give his sentiment on the mypy change / issue.

@@ -85,6 +84,8 @@ def cdk_template_path():
# Note: Don't move this into testing lib
@pytest.fixture(scope="session")
def infrastructure_setup(cdk_template_path, aws_client):
from localstack.testing.scenario.provisioning import InfraProvisioner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (non-blocking): ‏I think it would make sense to add a comment here explaining why it is important to have this import deferred. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I meant to do that and got distracted, will add!

@dfangl dfangl force-pushed the tests/defer-cdk-imports branch from b4a6071 to adc30c6 Compare May 7, 2025 14:16
@dfangl dfangl assigned bblommers and unassigned dfangl May 7, 2025
@bblommers
Copy link
Contributor

LGTM! As long as plux doesn't have any types, the specific type of ignore doesn't really matter IMO

@dfangl dfangl added this to the 4.4 milestone May 7, 2025
@dfangl dfangl merged commit fd727d5 into master May 7, 2025
27 of 28 checks passed
@dfangl dfangl deleted the tests/defer-cdk-imports branch May 7, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants