Prevent remaster from updating fallback versioned expected outputs#10953
Prevent remaster from updating fallback versioned expected outputs#10953mchris86 wants to merge 2 commits intopylint-dev:pytest-remasterfrom
Conversation
Adds tests for fallback detection
for more information, see https://pre-commit.ci
|
One thought while working on this: it might be useful for GoldenMaster to expose a compare-only mode, to avoid duplicating comparison logic when remastering is not desired |
|
Thank you for working on this.
That would be the |
|
I think What i meant here, is when This way, we could call something like |
I don't understand what it means, do you mind giving an example ? |
|
For example, suppose we have:
and we run the tests on Python 3.14. Since there is no In this case, |
|
Ha thank you for explaining. Yes it definitely need an evolution in pytest-remaster. Maybe an output name can take a callable (and in pylint we'd give a function that return a string based on the interpreter) ? What do you think ? |
|
The problem is that even if we pass a callable that returns a string, pytest-remaster still won't know if that path should be updated or not. That is why I am thinking it may be simpler to keep on the pylint side: if the output is a fallback (eg. I pushed a small implementation of this in this PR if that helps. |
Add resolve_with_override() utility and override_path parameter on GoldenMaster.check() to support version-specific expected output files. When provided, the override is used for comparison if it exists on disk, otherwise the base file is used. Remastering writes to the override path, keeping the base untouched. Redundant overrides identical to the base are automatically cleaned up. Includes a pylint-based demo (tests/demo_pylint/) exercising the feature with a custom checker that produces version-dependent output. Refs: pylint-dev/pylint#10844, pylint-dev/pylint#10953
|
Thanks for the discussion, I did some design in pytest-remaster to address this concern. I'd love your opinion on the "dimensions" parameter: golden_master.check(
lint_test.serialize_output(actual_output),
test_file.expected_output_base, # test.txt (generic)
dimensions={
"version": f"{sys.version_info[0]}{sys.version_info[1]}",
"platform": sys.platform,
},
) For version="314" on Linux, pytest-remaster generates and checks this chain: test.314.linux.txt → test.314.txt → test.linux.txt → test.txt If the new file is identical to a less specific one, it's automatically removed as redundant. It could also work with cpython/pypy or other specificity I possibly don't remember (python interpreter, py-version parameter, operating system and python implementation are already pretty covering I think). See feature branch: Pierre-Sassoulas/pytest-remaster#1 There's a pylint specific example with a cursed checker that has an output that differ for each python interpreters / platform : https://github.com/Pierre-Sassoulas/pytest-remaster/tree/pylint-functional-tests/tests/demo_pylint This is still a draft. Does this design work for the use case you had in mind, or do you see issues we should address? We can adjust the API if needed. |
|
Thanks for sharing this! I took some time go through the PR and the demo and I think the new design is really strong. One thing I wanted to ask: With: it looks like remaster will create the most specific file for the current run, for example: How would the less specific files be generated, like: Will new tests only contain this kind of expected files ( |
|
Right, for existing tests (the pylint migration case), the base file (test.txt) already exists. Dimensions add version/platform-specific overrides on top only when the output diverges. If an override matches a less-specific file, |
|
I think a simple approach could be:
For example: This way, we can keep the number of files minimal and add more only when needed. If we don't want to change current design, just creating the base test.txt for new tests would work too |
|
I released 0.0.5, we can refine it when we realize what's blocking. |
|
Good, I will integrate it with pylint and see how it works |
Adds tests for fallback detection
Type of Changes
Description
Refs #10844
This PR builds on the discussion in #10950 and adapts the fix to the
pytest-remasterbranch.When running functional tests on a newer Python version (e.g. 3.14) , pylint may fall back to an older versioned expected output file (e.g.
.313.txt) if no exact match exists. These fallback files are valid comparison targets but should not be updated/deleted.In the current implementation:
if
expected_outputresolves to a fallback file, it may be updated/deleted during remaster.This change detects fallback outputs and ensures they are only used for comparison.
For fallback cases, a compare-only check is done instead of calling
golden_master.check().Testing
Added tests for fallback detection logic