This repository has been archived by the owner on Apr 7, 2022. It is now read-only.
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.
When the provider marker has scope='module' (or anything other than function) set, the provider fixture was not properly scoped. The fixture, and any other fixtures depending on it, would teardown and setup between each test. This PR fixes that behavior with the following changes:
1.) De-duplicate the DataProvider instances created during test collection / parametrization, so that the same instance is always used for the same combination of provider category, type, and version. This is implemented by using a new class method in DataProvider, get_instance(), which stores previously-created instances in a private class-level attribute, _instances. This is a dictionary where the key is the tuple (category, type, version), and the value is the corresponding instance. In a sample test collection run, this drastically cut down the number of DataProvider instances created from 24,605 to 19.
2.) Use the DataProvider instance as the provider fixture's cache key. Previously, the BaseProvider subclass instance was stored here, but this instance is created for a test only after pytest checks whether the cache key of the test's fixture request matches the cached result from the previous fixture execution. Because the DataProvider instances have been de-duplicated and are created during test collection, using them as the key will guarantee that this check succeeds.
Before this fix, a pytest run with the --setup-show option would show teardown/setup of module-scoped fixtures between tests in the same module. With the fix, lines like the following between tests will no longer appear:
{{ pytest: -v --setup-show -m smoke }}