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
importreviewboard.testingon load. The problem there is that this
module forward-importsreviewboard.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).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 --helpwithout a crash.
| Summary | ID |
|---|---|
| a8dc79456c089fe5441107cf894bdf6482adc9bb |
| Description | From | Last Updated |
|---|---|---|
|
Can you add a module docstring while you're touching this? |
|
- Change Summary:
-
Added a module docstring.
- Commits:
-
Summary ID 73306c9b2ca9e0d630bf2b14210099701a788bbb a8dc79456c089fe5441107cf894bdf6482adc9bb - Diff:
-
Revision 2 (+100 -4)