Add extension state cleanup and new features in ExtensionTestCaseMixin.

Review Request #11925 — Created Jan. 11, 2022 and submitted — Latest diff uploaded

Information

Djblets
release-2.x

Reviewers

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 new reset_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
(unless allow_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
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. 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.

Commits

Files

    Loading...