Skip to content

refactor(tests): core logic unit tests to follow test conventions#3250

Open
agsaru wants to merge 6 commits into
Netflix:masterfrom
agsaru:refactor-pytest-unit-core
Open

refactor(tests): core logic unit tests to follow test conventions#3250
agsaru wants to merge 6 commits into
Netflix:masterfrom
agsaru:refactor-pytest-unit-core

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:19

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.

This PR refactors and modernizes a set of unit tests to improve readability, determinism, and maintainability by introducing fixtures, parametrization, clearer test naming, and stronger assertions.

Changes:

  • Refactored multiple unit tests to use pytest fixtures/parametrize patterns and clearer assertions.
  • Improved determinism in tests by avoiding reliance on ambient environment state (e.g., OS env, time-based uniqueness).
  • Reorganized test files with consistent section headers and more descriptive docstrings/ids.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/unit/test_tutorial_01_02_csv_parsing.py Parametrizes CSV parsing tests and adjusts sample CSV data/constants.
test/unit/test_task_log_metadata_fetch.py Adds parametrization ids and improves test organization/readability.
test/unit/test_system_context.py Consolidates repetitive tests via parametrization and improves naming/docstrings.
test/unit/test_sourceless_dag_node.py Introduces fixtures and strengthens assertions around sourceless graphs.
test/unit/test_secrets_decorator.py Improves determinism (env collision), adds ids/docstrings, and refactors assertions.
test/unit/test_remove_decorator.py Introduces a fixture for step setup and splits success/failure cases.
test/unit/test_pypi_parsers.py Uses pytest.raises, parametrizes requirements parsing, and improves naming.
test/unit/test_packaging_utils.py Parametrizes hidden-directory walk tests using tmp_path.
test/unit/test_package_suffixes_mutator.py Reworks tests with fixtures/factories and parametrizes init behavior.
test/unit/test_metaflow_version.py Adds parametrization ids for clearer test output.
test/unit/test_graph_structure.py Reorganizes tests/docs/ids and updates import ordering.
test/unit/test_graph_endpoints_fallback.py Adds constants, refactors helper naming, and clarifies behavior via assertions.
test/unit/test_config_value.py Adds fixtures/parametrization and broadens behavioral coverage.
test/unit/test_card_creator.py Improves mocking clarity via module path constants and adds docstrings.
test/unit/test_add_to_package.py Large refactor to fixtures/factories; improves readability and removes tempfiles usage.

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

Comment on lines 5 to 9
SAMPLE_CSV = (
"movie_title,title_year,genres,gross\n"
'"Monsters,\n Inc.",2001,"Animation|\nComedy",289907418\n'
'"Monsters, Inc.",2001,Animation|Comedy,289907418\n'
'"I, Robot",2004,Action|Sci-Fi,144795350\n'
)
Comment thread test/unit/test_tutorial_01_02_csv_parsing.py Outdated
Comment thread test/unit/test_graph_structure.py Outdated
Comment thread test/unit/test_secrets_decorator.py Outdated
Comment thread test/unit/test_packaging_utils.py Outdated
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors 15 unit-test files to follow pytest conventions: _make_* helper functions become factory fixtures backed by mocker, tmp_path replaces manual tempfile usage, monkeypatch/mocker replace direct unittest.mock imports, and every @pytest.mark.parametrize call gains an explicit ids list.

  • Fixture conversion (test_add_to_package.py, test_card_creator.py, test_package_suffixes_mutator.py, etc.): factory functions are now pytest fixtures that receive mocker, enabling automatic mock cleanup and better test isolation.
  • Parametrize ids everywhere: all parametrized tests now emit human-readable names in the test report instead of numeric indices.
  • test_tutorial_01_02_csv_parsing.py: parse_csv is updated to use io.StringIO(data) directly, and SAMPLE_CSV retains quoted fields with embedded newlines that the test also asserts are preserved correctly.

Confidence Score: 5/5

All changes are confined to test files with no production code touched; the refactoring is behaviorally equivalent to the prior implementation.

No production code is modified. The factory-fixture conversions, import cleanups, and parametrize-id additions preserve the original test logic exactly. The two findings in test_system_context.py are minor: inverted parametrize labels and a singleton reset fixture that only cleans up post-test rather than also pre-test.

test/unit/test_system_context.py — inverted parametrize IDs and a non-defensive autouse fixture.

Important Files Changed

Filename Overview
test/unit/test_add_to_package.py Helper functions converted to factory fixtures using mocker; setup_flow_dir now uses tmp_path; logic is equivalent.
test/unit/test_card_creator.py Module constants extracted; clean_card_process_registry fixture correctly clears state both before and after each test.
test/unit/test_config_value.py Module-level constants replaced with fixtures; mutation-method tests parametrized with explicit ids.
test/unit/test_system_context.py reset_singleton autouse fixture only resets after each test (not before); ids for test_shared_state_returns_none_for_missing_keys are inverted.
test/unit/test_graph_structure.py Fixtures parametrized with descriptive ids; negative-path tests added; _lint_warnings helper preserved.
test/unit/test_tutorial_01_02_csv_parsing.py Switched to io.StringIO(data); embedded-newline handling is covered by the test assertions.
test/unit/test_secrets_decorator.py Unified default_secrets_backend fixture added; all parametrized tests gained explicit ids.
test/unit/test_package_suffixes_mutator.py make_mutator factory fixture added; setup_flow_dir uses tmp_path; logic unchanged.
test/unit/test_packaging_utils.py Walk tests parametrized with explicit ids; exact set comparison asserts both inclusion and exclusion.
test/unit/test_metaflow_version.py Only change is addition of explicit ids to all three parametrize calls; no logic changes.
test/unit/test_graph_endpoints_fallback.py Module constant extracted; tests for missing metadata, cached MetaflowNotFound, and non-cached transient errors preserved.
test/unit/test_pypi_parsers.py Test constants moved to module level; requirements_txt_parser test parametrized with explicit ids.
test/unit/test_remove_decorator.py mock_step converted to pytest fixture; mocker.patch.object replaces context manager; logic equivalent.
test/unit/test_sourceless_dag_node.py Dynamic flow class extracted to fixture; module docstring expanded to document FunctionSpec context.
test/unit/test_task_log_metadata_fetch.py Constants extracted; fixtures introduced; stream parametrize calls gained explicit ids; logic unchanged.

Reviews (3): Last reviewed commit: "included the root basename" | Re-trigger Greptile

Comment thread test/unit/test_graph_structure.py Outdated
Comment thread test/unit/test_graph_structure.py Outdated
Comment thread test/unit/test_tutorial_01_02_csv_parsing.py
@agsaru agsaru marked this pull request as draft June 8, 2026 19:48
@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    #3250   +/-   ##
=========================================
  Coverage          ?   28.83%           
=========================================
  Files             ?      381           
  Lines             ?    52467           
  Branches          ?     9260           
=========================================
  Hits              ?    15131           
  Misses            ?    36327           
  Partials          ?     1009           

☔ 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 16:25
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