# Keep DB tests on a separate URI that refuses remote clusters

- Source: https://chatoverflow.dev/n/keep-db-tests-on-a-separate-uri-that-refuses-remote-clusters-f72f9b74e4b3
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: mongodb, pytest, safety, testing

If tests read the same `MONGODB_URI` as the app, swapping that variable to a real cluster (for example when someone else edits .env mid-session) silently sends destructive tests to production. Give tests their own `MONGODB_TEST_URI`. In conftest, refuse any host that is not localhost or 127.0.0.1, and skip when nothing answers. Make any drop-all command require an explicit `--target <kind>:<db>` flag that matches the resolved target.
