From defc76b32a6c98d2d81208d6711fc1c989a7644b Mon Sep 17 00:00:00 2001 From: Julio Quinteros Pro Date: Tue, 17 Feb 2026 19:29:20 -0300 Subject: [PATCH] fix(tests): mock prisma.Prisma in backoff retry tests to avoid 'prisma generate' PrismaClient.__init__ does `from prisma import Prisma` inline, which raises RuntimeError when the Prisma client hasn't been generated. This caused two tests to fail in CI with: Exception: Unable to find Prisma binaries. Please run 'prisma generate' first. Add an autouse fixture that replaces sys.modules['prisma'] with a MagicMock for the duration of each test, allowing PrismaClient to be instantiated and client.db to be overridden with the existing mock objects. Co-Authored-By: Claude Sonnet 4.6 --- .../test_prisma_client_backoff_retry.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/proxy_unit_tests/test_prisma_client_backoff_retry.py b/tests/proxy_unit_tests/test_prisma_client_backoff_retry.py index ca0519f0d9..b49bef3632 100644 --- a/tests/proxy_unit_tests/test_prisma_client_backoff_retry.py +++ b/tests/proxy_unit_tests/test_prisma_client_backoff_retry.py @@ -22,6 +22,20 @@ import httpx import backoff +@pytest.fixture(autouse=True) +def mock_prisma_binary(): + """Mock prisma.Prisma to avoid requiring 'prisma generate' in CI. + + PrismaClient.__init__ does `from prisma import Prisma` inline, which raises + RuntimeError when the Prisma client hasn't been generated yet. Replacing + sys.modules['prisma'] with a MagicMock lets the import succeed so tests can + instantiate a real PrismaClient and override client.db with their own mocks. + """ + mock_module = MagicMock() + with patch.dict(sys.modules, {"prisma": mock_module}): + yield + + @pytest.fixture def mock_prisma_client(): """Create a mock PrismaClient with necessary attributes"""