将干净引擎注入 api.app,返回 Flask test_client。 测试结束后恢复原始引擎,避免全局状态污染。
(_engine)
| 45 | |
| 46 | @pytest.fixture |
| 47 | def client(_engine): |
| 48 | """将干净引擎注入 api.app,返回 Flask test_client。 |
| 49 | |
| 50 | 测试结束后恢复原始引擎,避免全局状态污染。 |
| 51 | """ |
| 52 | import backend.api as api_module |
| 53 | |
| 54 | original = api_module.simulation_engine |
| 55 | api_module.simulation_engine = _engine |
| 56 | api_module.app.config["TESTING"] = True |
| 57 | try: |
| 58 | with api_module.app.test_client() as c: |
| 59 | yield c |
| 60 | finally: |
| 61 | api_module.simulation_engine = original |
| 62 | |
| 63 | |
| 64 | # --------------------------------------------------------------------------- |
nothing calls this directly
no outgoing calls
no test coverage detected