Skip to content

Commit cb0d544

Browse files
fix: Restore database.backend config after multi-backend tests
The connection_by_backend fixture was setting dj.config['database.backend'] globally without restoring it after tests, causing subsequent tests to run with the wrong backend (postgresql instead of mysql). Now saves and restores the original backend, host, and port configuration.
1 parent 450d2b9 commit cb0d544

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ def db_creds_by_backend(backend, mysql_container, postgres_container):
327327
@pytest.fixture(scope="session")
328328
def connection_by_backend(db_creds_by_backend):
329329
"""Create connection for the specified backend."""
330+
# Save original config to restore after tests
331+
original_backend = dj.config.get("database.backend", "mysql")
332+
original_host = dj.config.get("database.host")
333+
original_port = dj.config.get("database.port")
334+
330335
# Configure backend
331336
dj.config["database.backend"] = db_creds_by_backend["backend"]
332337

@@ -349,7 +354,14 @@ def connection_by_backend(db_creds_by_backend):
349354
)
350355

351356
yield connection
357+
358+
# Restore original config
352359
connection.close()
360+
dj.config["database.backend"] = original_backend
361+
if original_host is not None:
362+
dj.config["database.host"] = original_host
363+
if original_port is not None:
364+
dj.config["database.port"] = original_port
353365

354366

355367
# =============================================================================

0 commit comments

Comments
 (0)