Add extension state cleanup and new features in ExtensionTestCaseMixin.
Review Request #11925 — Created Jan. 11, 2022 and submitted
ExtensionTestCaseMixin
had 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
runs.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 newreset_extensions()
method, which is called on
tearDown()
but can also be called manually if a test requires it.A new
setup_extension()
method (ported over from the legacy
ExtensionTestsMixin
and 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
manager class.Previously,
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
(unlessallow_existing_extension_manager
is turned off), or
instantiate the default extension manager class for the test run.To make extensions available for
ExtensionManager.load()
, they can
callwith self.scanned_extensions([...])
with a list of extension
classes that have been already set up usingsetup_extension()
.This is a pretty comprehensive set of improvements, and will allow our
internal tests to switch over from the oldExtensionTestsMixin
. That
will be done in a future change to fix the rest of the extension state
leaks.As a new feature, this will require a .y version bump (to 2.3).
All unit tests pass under the old
nose
test runner.All unit tests pass under the new
pytest
test runner, in combination
with test suite updates to use this class.
Summary | ID |
---|---|
81e940e0619cc48fd65318073c851ecd4e9d2764 |
Description | From | Last Updated |
---|---|---|
F401 'kgb' imported but unused |
reviewbot |
- Change Summary:
-
- Added
scanned_extensions()
. - Changed
setup_extension()
to not return an instance unlessenable=True
. - Changed cleanup to better clean up classes in the correct extension managers.
- Added
- Description:
-
ExtensionTestCaseMixin
had a basic attempt at cleaning up state, butit never actually unregistered extension classes, and any additional extensions registered during a unit test would leak into other test runs. 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 ontearDown()
but can also be called manually if a test requires it.A new
setup_extension()
method (ported over from the legacyExtensionTestsMixin
and enhanced) can be used by unit tests toregister and construct other extensions. setUp()
now calls this whenthe 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 manager class. Previously,
get_extension_manager()
would require an existingextension 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 (unless allow_existing_extension_manager
is turned off), orinstantiate the default extension manager class for the test run. + To make extensions available for
ExtensionManager.load()
, they can+ call with self.scanned_extensions([...])
with a list of extension+ classes that have been already set up using setup_extension()
.+ This is a pretty comprehensive set of improvements, and will allow our
internal tests to switch over from the old ExtensionTestsMixin
. Thatwill be done in a future change to fix the rest of the extension state leaks. As a new feature, this will require a .y version bump (to 2.3).
- Commits:
-
Summary ID ea156c6f55b3bb17ca5c0f481bbd7c3d3de48065 6e7fde2549bbbb3e3cd888a277ab7a62fa6bc8d2 - Diff:
-
Revision 2 (+818 -52)
Checks run (2 succeeded)
- Change Summary:
-
Updated
scanned_extensions()
to not requiresetup_extension()
first. - Commits:
-
Summary ID 6e7fde2549bbbb3e3cd888a277ab7a62fa6bc8d2 81e940e0619cc48fd65318073c851ecd4e9d2764 - Diff:
-
Revision 3 (+854 -52)