Add auto-update system for integration test hardcoded expectations #42579
+653
−83
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.
This PR introduces a decorator-based system to automatically update hardcoded values in integration tests, making them easier to maintain when switching to different hardware, or other changes impact a large amount of integration tests.
For context, another PR I'm working on to load fast image processors by default (#41388) is breaking a lot of integration tests, which is expected, but really annoying to manually fix. I could instead force all the tests to use slow image processor, but that would just be postponing fixing this issue, as we might fully deprecate slow image processors in the future.
The new
@record_expectationsdecorator automatically captures actual values from tests and updates hardcoded expected values directly in the source file when running withUPDATE_EXPECTATIONS=1.How to use in the test files
Basic usage:
This also works with the recently introduced
Expectationsobject, where values will be updated only for the current hardware configuration. Cc @ydshiehWe could also add flags to decide what we want to update (
("cuda", None) by default? or specific hardware("cuda", (8, 6) by default?). I'm not fully sure what would be best here, so I'd love to hear your thoughtsHow to update hardcoded values
To update expectations, we can just pass the
UPDATE_EXPECTATIONS=1flag to the usual pytest commands:I only added the decorators and made other necessary modifications for a few modeling tests for now, but happy to extend this to others once I get some feedback
I think this could make our lives easier, but I'd love to have your thoughts on this!
Cc @ydshieh @ArthurZucker @Cyrilvallez @molbap @zucchini-nlp