|
34 | 34 | logger = logging.getLogger(__name__) |
35 | 35 |
|
36 | 36 |
|
| 37 | +def pytest_sessionstart(session): |
| 38 | + """Called after the Session object has been created and configured.""" |
| 39 | + # This runs very early, before most fixtures, but we don't have container info yet |
| 40 | + pass |
| 41 | + |
| 42 | + |
| 43 | +def pytest_configure(config): |
| 44 | + """Called after command line options have been parsed.""" |
| 45 | + # This runs before pytest_sessionstart but still too early for containers |
| 46 | + pass |
| 47 | + |
| 48 | + |
37 | 49 |
|
38 | 50 |
|
39 | 51 | # Global container registry for cleanup |
@@ -313,17 +325,30 @@ def db_creds_test(mysql_container) -> Dict: |
313 | 325 | ) |
314 | 326 |
|
315 | 327 |
|
316 | | -@pytest.fixture(scope="session") |
317 | | -def db_creds_root(mysql_container) -> Dict: |
| 328 | +@pytest.fixture(scope="session", autouse=True) |
| 329 | +def configure_datajoint_for_containers(mysql_container): |
| 330 | + """Configure DataJoint to use pytest-managed containers. Runs automatically for all tests.""" |
318 | 331 | _, host, port = mysql_container |
319 | | - # Set environment variables for DataJoint at module level |
| 332 | + |
| 333 | + # Set environment variables FIRST - these will be inherited by subprocesses |
| 334 | + logger.info(f"🔧 Setting environment: DJ_HOST={host}, DJ_PORT={port}") |
320 | 335 | os.environ["DJ_HOST"] = host |
321 | 336 | os.environ["DJ_PORT"] = str(port) |
322 | 337 |
|
323 | | - # Also update DataJoint's configuration directly |
| 338 | + # Verify the environment variables were set |
| 339 | + logger.info(f"🔧 Environment after setting: DJ_HOST={os.environ.get('DJ_HOST')}, DJ_PORT={os.environ.get('DJ_PORT')}") |
| 340 | + |
| 341 | + # Also update DataJoint's configuration directly for in-process connections |
324 | 342 | dj.config["database.host"] = host |
325 | 343 | dj.config["database.port"] = port |
326 | 344 |
|
| 345 | + logger.info(f"🔧 Configured DataJoint to use MySQL container at {host}:{port}") |
| 346 | + return host, port # Return values so other fixtures can use them |
| 347 | + |
| 348 | + |
| 349 | +@pytest.fixture(scope="session") |
| 350 | +def db_creds_root(mysql_container) -> Dict: |
| 351 | + _, host, port = mysql_container |
327 | 352 | return dict( |
328 | 353 | host=f"{host}:{port}", |
329 | 354 | user=os.getenv("DJ_USER", "root"), |
|
0 commit comments