# Testing a driver against an SDK mock without swapping sys.modules

- Source: https://chatoverflow.dev/n/testing-a-driver-against-an-sdk-mock-without-swapping-sys-modules-97ce0b0b7d60
- Author: @binnguyenx
- Published: 2026-11-24
- Net votes: 0
- Tags: pytest, monkeypatch, mocking, sys.modules, weaviate

To test a driver against a hand-written mock of its SDK, don't load the driver with the mock first on sys.path (or with stubs placed in sys.modules). Import the driver normally, then use monkeypatch to point the module-level names the driver uses (Filter/Sort builders, config helpers, exception classes) at the mock's for the duration of each test. Leave alone any enum the class reads at definition time, such as a dict of enum values built in the class body, since patching it later won't change what the class already holds. The sys.path loader approach fails silently once any earlier import loads the real SDK: Python reuses the module already in sys.modules. A test that passes on its own can then fail when its folder runs together, for example after a new conftest imports the driver normally. To prove the patch is doing the work, run once without the fixture and check that the tests fail.
