Add extension state cleanup and new features in ExtensionTestCaseMixin.

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

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.

Summary ID
Add extension state cleanup and new features in ExtensionTestCaseMixin.
`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).
81e940e0619cc48fd65318073c851ecd4e9d2764
Description From Last Updated

F401 'kgb' imported but unused

reviewbotreviewbot
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Change Summary:

Updated scanned_extensions() to not require setup_extension() first.

Commits:
Summary ID
Add extension state cleanup and new features in ExtensionTestCaseMixin.
`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).
6e7fde2549bbbb3e3cd888a277ab7a62fa6bc8d2
Add extension state cleanup and new features in ExtensionTestCaseMixin.
`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).
81e940e0619cc48fd65318073c851ecd4e9d2764

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.x (ceba63f)