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.
Use session-scoped pytest yield fixtures, custom parametrization, and filelock to generate files in the proper order, serially or in parallel via pytest-xdist.
The basic problem this solves is: can we use pytest to generate files, where some files depend on other files being created first, while parallelizing non-dependent file creation as much as possible?
How it works
Use
pytest_generate_tests
to enumerate "source" data files. Define fixtures, parametrized with the source data files, to convert to intermediate data files (kind of like rules in GNU make). Define test functions which consume the fixtures and make intermediate files. Define session-scoped yield fixtures to generate final data files, but only after yielding (at which point intermediate files already exist). Use filelock as suggested in pytest-xdist docs to protect the critical section (containing the yield statement and code to generate the final file) in the session-scoped fixtures. Define test functions consuming the session-scoped fixtures. We're done!All the real work is done in test fixtures. Test functions are only used to invoke the fixtures. Test functions can be thought of like the top-level rule defining a makefile's targets.
If we didn't need to support xdist/parallel, yield fixtures would suffice. The filelock just makes sure only one worker process creates the final file(s).