Lazy-load TestCase to preventing pytest crashes.

Review Request #13324 — Created Oct. 9, 2023 and submitted — Latest diff uploaded

Information

Review Board
release-6.x

Reviewers

In Review Board 6, the pytest fixtures were moved into
reviewboard.testing.pytest_fixtures. This caused pytest to have to
import reviewboard.testing on load. The problem there is that this
module forward-imports reviewboard.testing.testcase.TestCase, and this
module depends on a working Django environment first. That causes a
crash for pytest help output or operations that don't require setting up
a test environment.

We now lazily-import TestCase in this module so that we only pull it
in when explicitly requested. This is done through a module-level
__getattr__ (available in all supported versions of Python).

A TYPE_CHECKING-level import is done to ensure that importers see the
right type for this class.

Unit tests pass on Python 3.8-3.11.

I can run pytest --help without a crash.

Commits

Files

    Loading...