Lazy-load TestCase to preventing pytest crashes.
Review Request #13324 — Created Oct. 9, 2023 and submitted
In Review Board 6, the pytest fixtures were moved into
reviewboard.testing.pytest_fixtures. This caused pytest to have to
reviewboard.testingon load. The problem there is that this
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
TestCasein 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).
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 --helpwithout a crash.