import pytest def test_check_migration_out_of_sync(mocker): """ Test that the check_prisma_schema_diff function - 🚨 [IMPORTANT] Does NOT Raise an Exception when the Prisma schema is out of sync with the database. - logs an error when the Prisma schema is out of sync with the database. """ # Import the module first so check_migration is in sys.modules, # then patch the logger reference in that module directly (not the source # module) so the patch works regardless of import order or xdist worker # assignment. from litellm.proxy.db import check_migration # Mock the helper function to simulate out-of-sync state mock_logger = mocker.patch.object( check_migration, "verbose_logger", autospec=True, ) mocker.patch.object( check_migration, "check_prisma_schema_diff_helper", return_value=(True, ["ALTER TABLE users ADD COLUMN new_field TEXT;"]), ) # Run the function - it should not raise an error try: check_migration.check_prisma_schema_diff(db_url="mock_url") except Exception as e: pytest.fail(f"check_prisma_schema_diff raised an unexpected exception: {e}") # Verify the logger was called with the expected message check_migration.verbose_logger.exception.assert_called_once() actual_message = check_migration.verbose_logger.exception.call_args[0][0] assert "prisma schema out of sync with db" in actual_message