Skip to content

Add a scoped_env utility for tests - #4474

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
zcbenz:scoped-env
Sep 8, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
zcbenz:scoped-env

Conversation

@zcbenz

@zcbenz zcbenz commented Sep 8, 2026

Copy link
Copy Markdown
Member

Replace a common pattern in tests:

        name = "MLX_SDPA_PAD_HEAD_DIM"
        previous = os.environ.get(name)
        try:
            os.environ[name] = "1"
            run_tests()
        finally:
            if previous is None:
                os.environ.pop(name, None)
            else:
                os.environ[name] = previous

With a utility:

        with mlx_tests.scoped_env(MLX_SDPA_PAD_HEAD_DIM=1):
            run_tests()

@nastya236 nastya236 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you! Very nice refactoring!

@zcbenz
zcbenz merged commit ec5f6ff into ml-explore:main Sep 8, 2026
29 checks passed
@zcbenz
zcbenz deleted the scoped-env branch September 8, 2026 11:14
aaishwarymishra pushed a commit to aaishwarymishra/mlx that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants