Skip to content

refactor(tests): unit test submodules to follow test conventions#3248

Open
agsaru wants to merge 4 commits into
Netflix:masterfrom
agsaru:refactor-pytest-unit-submodules
Open

refactor(tests): unit test submodules to follow test conventions#3248
agsaru wants to merge 4 commits into
Netflix:masterfrom
agsaru:refactor-pytest-unit-submodules

Conversation

@agsaru

@agsaru agsaru commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

PR Type

  • Bug fix
  • New feature
  • Core Runtime change (higher bar -- see CONTRIBUTING.md)
  • Docs / tooling
  • Refactoring

Summary

Copilot AI review requested due to automatic review settings June 8, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors and reorganizes the Python unit/integration tests to be more consistent, readable, and maintainable—primarily by converting class-based tests into function tests, introducing shared fixtures, and consolidating repeated assertions via parametrization.

Changes:

  • Convert multiple test modules from class-based tests to function-based tests, adding shared fixtures where helpful.
  • Consolidate repeated assertions using pytest.mark.parametrize for graph inference, configs, and inheritance tests.
  • Improve localbatch docker skipping behavior by centralizing docker availability checks for @pytest.mark.docker tests.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/unit/spin/test_spin.py Reorganizes spin tests with clearer sections/names and removes debug prints.
test/unit/mutators/test_string_step_mutator.py Converts class-based tests to standalone functions with docstrings.
test/unit/mutators/test_remove_decorator_guard.py Replaces helper with a fixture factory and flattens tests to functions.
test/unit/mutators/test_post_step_none_false.py Converts class-based regression tests to explicit standalone tests.
test/unit/mutators/test_flow_mutator_addition.py Converts class-based tests to functions; adds clearer separation/comments.
test/unit/mutators/test_dual_inheritance.py Adds shared fixtures for task data; converts to function tests.
test/unit/mutators/test_add_decorator_returns.py Adds shared fixture for task data and expands test descriptions.
test/unit/localbatch/test_localbatch.py Flattens tests, adds an autouse docker-skip fixture, and improves organization.
test/unit/inheritance/test_inheritance.py Reorganizes inheritance tests into themed sections and parametrized integration tests.
test/unit/graph_inference/test_graph_inference.py Consolidates repeated “shape” assertions using parametrization and groups edge cases.
test/unit/graph_inference/test_card_dag.py Introduces fixtures for graph inputs and clarifies helper docstring.
test/unit/configs/test_config_plain.py Replaces repetitive assertions with parametrized checks plus focused property tests.
test/unit/configs/test_config_naming.py Parametrizes underscore/dash/mixed naming assertions to reduce duplication.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to 32
def test_simple_flows_validate_artifacts(flow_file, fixture_name, request):
"""Test that basic flows run steps correctly and validate their artifacts."""
run = request.getfixturevalue(fixture_name)
print(f"Running test for {flow_file}: {run}")

# Act & Assert: Iterate through and run each step
for step in run.steps():
print("-" * 100)
if fixture_name == "complex_dag_run":
run_step(flow_file, run, step.id, environment="conda")
else:
run_step(flow_file, run, step.id)
Comment thread test/unit/localbatch/test_localbatch.py Outdated
Comment thread test/unit/localbatch/test_localbatch.py Outdated
Comment thread test/unit/spin/test_spin.py Outdated
Comment on lines +193 to +208
def test_spin_generates_cards_correctly(simple_card_run):
"""Test that spinning a flow with the @card decorator successfully outputs cards."""
# Setup
from metaflow.cards import get_cards

step_name = "start"
task = simple_card_run[step_name].task
flow_path = os.path.join(FLOWS_DIR, "simple_card_flow.py")
print(f"Running test for cards in {flow_path}: {simple_card_run}")

# Act
with Runner(flow_path, cwd=FLOWS_DIR).spin(task.pathspec, persist=True) as spin:
spin_task = spin.task
from metaflow.cards import get_cards
res = get_cards(spin.task, follow_resumed=False)

res = get_cards(spin_task, follow_resumed=False)
print(res)
# Assert
assert res is not None, "Cards should be generated and retrievable"
# Optional: assert len(res) > 0 if you expect a specific number of cards
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors 12 unit test submodules across configs, graph_inference, inheritance, mutators, and spin to follow pytest conventions: test classes are replaced with module-level functions, repeated fixture lookups are extracted into helper fixtures, and parametrize decorators consolidate near-identical tests.

  • All test classes are flattened to standalone functions; debug print statements are removed and replaced with Setup/Act/Assert structure and proper docstrings.
  • Repeated assertions across per-fixture test variants are collapsed into parametrized tests using request.getfixturevalue; inline data dicts are promoted to named fixtures.
  • The pre-existing broken assert_artifacts import and dangling call in test_spin.py are removed, and the test_card_flow test gains real assertions in place of bare print statements.

Confidence Score: 5/5

Pure structural refactoring of test files with no changes to production code; all original assertions are preserved.

Every original assertion is accounted for in the refactored code. The cards test gains stronger coverage with real assertions replacing bare print statements, and the broken assert_artifacts call from a previous review is resolved. No fixture scoping issues were found.

No files require special attention.

Important Files Changed

Filename Overview
test/unit/graph_inference/test_graph_inference.py ~100 lines of repetitive per-flow tests collapsed into parametrized tests using request.getfixturevalue; an explicit start_step == end_step identity assertion from the original single-step test is implicitly preserved since both values are independently asserted to equal "only".
test/unit/spin/test_spin.py All debug print statements removed; broken assert_artifacts import and call removed (addressing a pre-existing bug); cards test now adds real assertions; Setup/Act/Assert structure added throughout.
test/unit/inheritance/test_inheritance.py Four test classes flattened into module-level functions with descriptive names; integration parametrize tests preserved with explicit ids added.
test/unit/mutators/test_add_decorator_returns.py Class flattened; task data extraction factored into a reusable start_task_data fixture shared across five tests.
test/unit/mutators/test_remove_decorator_guard.py Module-level _make_mutable_step helper converted to a factory fixture; class replaced by three standalone functions.
test/unit/configs/test_config_naming.py Flattened class to module-level functions; three separate naming-format tests consolidated into one parametrized test with explicit ids.
test/unit/configs/test_config_plain.py Class flattened to functions; type/value assertions moved to a parametrized test while list/tuple property assertions extracted to dedicated helpers; also fixes == True to is True.
test/unit/graph_inference/test_card_dag.py Inline graph dicts promoted to named pytest fixtures; docstring added to the recursive helper.
test/unit/mutators/test_dual_inheritance.py Class replaced by module-level functions; start_task_data and end_task_data fixtures introduced to avoid repeated task lookups.
test/unit/mutators/test_flow_mutator_addition.py Two inner classes flattened to module-level functions with section comments replacing class docstrings.
test/unit/mutators/test_post_step_none_false.py Single-class file flattened to three standalone functions; docstrings tightened.
test/unit/mutators/test_string_step_mutator.py Minimal class unwrapped to two standalone functions; docstrings added.

Reviews (4): Last reviewed commit: "revert test_simple_flows_validate_artifa..." | Re-trigger Greptile

Comment thread test/unit/spin/test_spin.py Outdated
Comment thread test/unit/localbatch/test_localbatch.py Outdated
@agsaru agsaru marked this pull request as draft June 8, 2026 19:47
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@732ca76). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #3248   +/-   ##
=========================================
  Coverage          ?   28.85%           
=========================================
  Files             ?      381           
  Lines             ?    52467           
  Branches          ?     9260           
=========================================
  Hits              ?    15138           
  Misses            ?    36315           
  Partials          ?     1014           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@agsaru agsaru marked this pull request as ready for review June 9, 2026 04:18
Comment thread test/unit/spin/test_spin.py Outdated
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