Skip to content

Allow multiple cases per fixture file#5149

Open
Pedro-Muller29 wants to merge 8 commits into
psf:mainfrom
Pedro-Muller29:feat/4506-multi-cell-fixtures
Open

Allow multiple cases per fixture file#5149
Pedro-Muller29 wants to merge 8 commits into
psf:mainfrom
Pedro-Muller29:feat/4506-multi-cell-fixtures

Conversation

@Pedro-Muller29
Copy link
Copy Markdown
Contributor

Fixes #4506.

Description

In #4506, MeGaGiGaGon flagged that the longest fixture files in tests/data/cases/ are painful to work with. preview_long_strings.py and preview_long_strings__regression.py are both 1000+ lines: input and output for any given case sit hundreds of lines apart, and when a test fails the assertion points at the end-of-file mismatch with nothing tying it back to the original case.

MeGaGiGaGon's first proposal was to split big files into folders of numbered files. JelleZijlstra pushed back on numbering ("renumbering files would be needlessly annoying") and suggested an alternative shape: sections within larger files, like mypy's test data format.

This PR takes the mypy-style path. Fixture files can group multiple cases under [case <name>] headers, and the two longest files are migrated as the first consumers.

# flags: --unstable

[case assign_x_1]
x = "..."
# output
x = (
    "..."
)

[case assign_y]
y = "Short string"
# output
y = "Short string"

The format is opt-in. Files without a [case ] header at the top run through the legacy single-case loader unchanged. Cell names appear in pytest IDs (test_simple_format[preview_long_strings::assign_x_1]), and on failure the assertion message attaches the file path, the cell header line, and the # output marker line, so the traceback points at the case under test rather than the file boundary.

A # flags: line above the first [case ] applies to every cell, and cell flags take precedence on overlap. That makes preview-to-stable migrations more granular: cells can graduate one at a time, while neighbors in the same file keep their preview flags.

Documentation in docs/contributing/the_basics.md covers the format and the merge semantics.

I picked preview_long_strings* for the first migrations because they're the worst offenders on file length.

Checklist - did you ...

  • Implement any code style changes under the --preview style, following the stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@cobaltt7 cobaltt7 added the ci: skip news Pull requests that don't need a changelog entry. label May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci: skip news Pull requests that don't need a changelog entry.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test organization improvements

2 participants