Set up a temporary database for each test.
(self, tmp_path)
| 486 | |
| 487 | @pytest.fixture(autouse=True) |
| 488 | def setup_db(self, tmp_path): |
| 489 | """Set up a temporary database for each test.""" |
| 490 | import utils.database as db_module |
| 491 | |
| 492 | test_db_path = tmp_path / 'test.db' |
| 493 | original_db_path = db_module.DB_PATH |
| 494 | db_module.DB_PATH = test_db_path |
| 495 | db_module.DB_DIR = tmp_path |
| 496 | |
| 497 | if hasattr(db_module._local, 'connection') and db_module._local.connection: |
| 498 | db_module._local.connection.close() |
| 499 | db_module._local.connection = None |
| 500 | |
| 501 | init_db() |
| 502 | |
| 503 | yield |
| 504 | |
| 505 | if hasattr(db_module._local, 'connection') and db_module._local.connection: |
| 506 | db_module._local.connection.close() |
| 507 | db_module._local.connection = None |
| 508 | db_module.DB_PATH = original_db_path |
| 509 | |
| 510 | def test_store_push_payload(self): |
| 511 | """store_push_payload should insert payload.""" |