mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-17 21:58:22 +03:00
fix test pollution
test_maintainer was injecting MagicMock() into sys.modules["frigate.config.camera.updater"] at module load time and never restoring it. When the profile tests later imported CameraConfigUpdateEnum and CameraConfigUpdateTopic from that module, they got mock objects instead of the real dataclass/enum, so equality comparisons always failed
This commit is contained in:
parent
0835aa7ea5
commit
67604eb61d
@ -2,16 +2,29 @@ import sys
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
# Mock complex imports before importing maintainer
|
# Mock complex imports before importing maintainer, saving originals so we can
|
||||||
sys.modules["frigate.comms.inter_process"] = MagicMock()
|
# restore them after import and avoid polluting sys.modules for other tests.
|
||||||
sys.modules["frigate.comms.detections_updater"] = MagicMock()
|
_MOCKED_MODULES = [
|
||||||
sys.modules["frigate.comms.recordings_updater"] = MagicMock()
|
"frigate.comms.inter_process",
|
||||||
sys.modules["frigate.config.camera.updater"] = MagicMock()
|
"frigate.comms.detections_updater",
|
||||||
|
"frigate.comms.recordings_updater",
|
||||||
|
"frigate.config.camera.updater",
|
||||||
|
]
|
||||||
|
_originals = {name: sys.modules.get(name) for name in _MOCKED_MODULES}
|
||||||
|
for name in _MOCKED_MODULES:
|
||||||
|
sys.modules[name] = MagicMock()
|
||||||
|
|
||||||
# Now import the class under test
|
# Now import the class under test
|
||||||
from frigate.config import FrigateConfig # noqa: E402
|
from frigate.config import FrigateConfig # noqa: E402
|
||||||
from frigate.record.maintainer import RecordingMaintainer # noqa: E402
|
from frigate.record.maintainer import RecordingMaintainer # noqa: E402
|
||||||
|
|
||||||
|
# Restore original modules (or remove mock if there was no original)
|
||||||
|
for name, orig in _originals.items():
|
||||||
|
if orig is None:
|
||||||
|
sys.modules.pop(name, None)
|
||||||
|
else:
|
||||||
|
sys.modules[name] = orig
|
||||||
|
|
||||||
|
|
||||||
class TestMaintainer(unittest.IsolatedAsyncioTestCase):
|
class TestMaintainer(unittest.IsolatedAsyncioTestCase):
|
||||||
async def test_move_files_survives_bad_filename(self):
|
async def test_move_files_survives_bad_filename(self):
|
||||||
|
|||||||
BIN
test.db-journal
Normal file
BIN
test.db-journal
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user