From baf7980cd6080c8cb4e6c6b585948144273600aa Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 14 Nov 2022 18:02:55 +0300 Subject: tests: split test app and test client * The test app and the test client are both needed as fixtures in different places --- tests/unit/conftest.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index a2b562e..9660c32 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -8,19 +8,24 @@ import pytest from gn3.app import create_app @pytest.fixture(scope="session") -def client(): - """Create a test client fixture for tests""" +def test_app(): # Do some setup with TemporaryDirectory() as testdir: testdb = Path(testdir).joinpath( f'testdb_{datetime.now().strftime("%Y%m%dT%H%M%S")}') - app = create_app({"AUTH_DB": testdb}) - app.config.update({"TESTING": True}) + app = create_app() + app.config.update({"TESTING": True, "AUTH_DB": testdb}) app.testing = True - yield app.test_client() + yield app # Clean up after ourselves testdb.unlink(missing_ok=True) +@pytest.fixture(scope="session") +def client(test_app): + """Create a test client fixture for tests""" + with test_app.app_context(): + yield test_app.test_client() + @pytest.fixture(scope="session") def test_app_config(client): # pylint: disable=redefined-outer-name """Return the test application's configuration object""" -- cgit v1.2.3