Add extension state cleanup and new features in ExtensionTestCaseMixin.
Review Request #11925 — Created Jan. 11, 2022 and submitted — Latest diff uploaded
ExtensionTestCaseMixinhad a basic attempt at cleaning up state, but
it never actually unregistered extension classes, and any additional
extensions registered during a unit test would leak into other test
Now, it carefully goes through all new extensions that were registered,
and new extension managers, and tries to clear them out. This logic
lives in the new
reset_extensions()method, which is called on
tearDown()but can also be called manually if a test requires it.
setup_extension()method (ported over from the legacy
ExtensionTestsMixinand enhanced) can be used by unit tests to
register and construct other extensions.
setUp()now calls this when
the class-level extension definition attributes are provided.
New class-level attributes have also been added to control whether an
extension should be enabled by default, and for the default extension
get_extension_manager()would require an existing
extension manager to be created, and would use it, but this led to
issues when extension managers leaked, or for projects that didn't
establish one for the test run. Now, it'll use an existing one if found
allow_existing_extension_manageris turned off), or
instantiate the default extension manager class for the test run.
To make extensions available for
ExtensionManager.load(), they can
with self.scanned_extensions([...])with a list of extension
classes that have been already set up using
This is a pretty comprehensive set of improvements, and will allow our
internal tests to switch over from the old
will be done in a future change to fix the rest of the extension state
As a new feature, this will require a .y version bump (to 2.3).
All unit tests pass under the old
All unit tests pass under the new
pytesttest runner, in combination
with test suite updates to use this class.