| 36 | def env_fixture(name, **kwargs): # place this fixture BEFORE app or its dependencies |
| 37 | """Produces a fixture that mocks a test parameter directly in an env var (before app init)""" |
| 38 | def _env_fixture(dbfile, monkeypatch, request): |
| 39 | if request.param is not None: # default value placeholder |
| 40 | monkeypatch.setenv(name, str(request.param)) |
| 41 | app = server.create_app(dbfile) |
| 42 | app.config.update({'TESTING': True, 'WTF_CSRF_ENABLED': False}) |
| 43 | yield request.param |
| 44 | flask.g.bukudb.close() |
| 45 | if os.path.exists(dbfile): |
| 46 | os.remove(dbfile) |
| 47 | return pytest.fixture(**kwargs)(_env_fixture) |
| 48 | |
| 49 | |