| Total Complexity | 3 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | """Defines fixtures available to all tests.""" |
||
| 3 | |||
| 4 | import logging |
||
| 5 | |||
| 6 | import pytest |
||
| 7 | |||
| 8 | from loglan_db import db as _db, create_app |
||
| 9 | |||
| 10 | |||
| 11 | @pytest.fixture |
||
| 12 | def app(): |
||
| 13 | """Create application for the tests.""" |
||
| 14 | _app = create_app("tests.settings", _db) |
||
| 15 | _app.logger.setLevel(logging.CRITICAL) |
||
| 16 | ctx = _app.test_request_context() |
||
| 17 | ctx.push() |
||
| 18 | |||
| 19 | yield _app |
||
| 20 | |||
| 21 | ctx.pop() |
||
| 22 | |||
| 23 | |||
| 24 | @pytest.fixture |
||
| 25 | def db(app): |
||
| 26 | """Create database for the tests.""" |
||
| 27 | _db.app = app |
||
| 28 | with app.app_context(): |
||
| 29 | _db.create_all() |
||
| 30 | |||
| 31 | yield _db |
||
| 32 | |||
| 33 | # Explicitly close DB connection |
||
| 34 | _db.session.close() |
||
| 35 | _db.drop_all() |
||
| 36 |