feat(testing): Add pytest fixtures for FlyteContext, cache, and tmp dirs#3411
Open
mvanhorn wants to merge 1 commit intoflyteorg:masterfrom
Open
feat(testing): Add pytest fixtures for FlyteContext, cache, and tmp dirs#3411mvanhorn wants to merge 1 commit intoflyteorg:masterfrom
mvanhorn wants to merge 1 commit intoflyteorg:masterfrom
Conversation
…, and tmp dirs Add three pytest fixtures to flytekit.testing that eliminate common test boilerplate: - flyte_context: provides the current FlyteContext without manually calling FlyteContextManager.current_context() - flyte_cache: auto-initializes and clears LocalTaskCache before/after each test, preventing stale cache from causing flaky tests (see flyteorg/flyte#5657) - flyte_tmp_dir: provides a managed temporary directory Also adds workflow_dry_run() context manager for running workflows locally with a clean cache state. Fixtures are auto-registered via pytest11 entry point in pyproject.toml, so they're available in any pytest session without explicit imports. Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
c37e8c6 to
d285c5f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three pytest fixtures and a context manager to
flytekit.testing, eliminating common test setup boilerplate. Fixtures auto-register via apytest11entry point so they're available without explicit imports.Why this matters
Flytekit's testing module currently ships two utilities (
task_mockandpatch). Users writing tests for Flyte workflows repeat the same boilerplate across test files:FlyteContextManager.current_context()to get a context - appears 30+ times in flytekit's own test suiteLocalTaskCache.initialize()/LocalTaskCache.clear()before cached task tests - the manual workaround discovered in flyteorg/flyte#5657tempfile.TemporaryDirectory()setup for file-based operationsOther workflow orchestrator SDKs ship dedicated testing utilities (Dagster's
execute_in_process(), Prefect'sprefect_test_harness, Airflow'spytest-airflow).Changes
New files:
flytekit/testing/fixtures.py- Three fixtures and one context manager:flyte_context- returns the currentFlyteContextflyte_cache- initializes and clearsLocalTaskCachebefore/after each testflyte_tmp_dir- provides a managedPathtemporary directoryworkflow_dry_run()- context manager for clean local workflow executionflytekit/testing/conftest.py- pytest11 plugin entry point for auto-discoverytests/flytekit/unit/testing/test_fixtures.py- 12 tests covering all fixturesModified files:
flytekit/testing/__init__.py- exports new fixturespyproject.toml- registers[project.entry-points.pytest11]so fixtures are auto-availableUsage
Testing
All 12 tests pass locally on Python 3.12:
Tests verify fixture behavior, cache isolation between tests, type transformations with context, and workflow dry-run execution.
This contribution was developed with AI assistance (Claude Code).