diff options
| author | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-07 12:52:46 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-10-07 12:52:46 -0500 |
| commit | 02ffa57d454f162ce77b1ebacb92dad1adff2e45 (patch) | |
| tree | 1dbb717d8988f9650a02c80b5ac47d36ad99494f | |
| parent | b40cd55da0fa230e2b9c071950e62335d5f1b6ef (diff) | |
| download | gn-auth-02ffa57d454f162ce77b1ebacb92dad1adff2e45.tar.gz | |
Make all fixtures 'function' scoped.
| -rw-r--r-- | tests/unit/auth/fixtures/migration_fixtures.py | 10 | ||||
| -rw-r--r-- | tests/unit/auth/fixtures/user_fixtures.py | 2 | ||||
| -rw-r--r-- | tests/unit/conftest.py | 8 |
3 files changed, 10 insertions, 10 deletions
diff --git a/tests/unit/auth/fixtures/migration_fixtures.py b/tests/unit/auth/fixtures/migration_fixtures.py index 1feb279..fe0ec1e 100644 --- a/tests/unit/auth/fixtures/migration_fixtures.py +++ b/tests/unit/auth/fixtures/migration_fixtures.py @@ -7,12 +7,12 @@ from yoyo.migrations import Migration, MigrationList from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import apply_migrations, rollback_migrations -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def auth_testdb_path(fxtr_startup_configs): # pylint: disable=redefined-outer-name """Get the test application's auth database file""" return fxtr_startup_configs["AUTH_DB"] -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def auth_migrations_dir(fxtr_startup_configs): # pylint: disable=redefined-outer-name """Get the test application's auth database file""" return fxtr_startup_configs["AUTH_MIGRATIONS"] @@ -25,18 +25,18 @@ def rollback_single_migration(backend: DatabaseBackend, migration: Migration):# """Utility to rollback a single migration""" rollback_migrations(backend, MigrationList([migration])) -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def backend(auth_testdb_path):# pylint: disable=redefined-outer-name """Fixture: retrieve yoyo backend for auth database""" return get_backend(f"sqlite:///{auth_testdb_path}") -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def all_migrations(auth_migrations_dir): # pylint: disable=redefined-outer-name """Retrieve all the migrations""" return read_migrations(auth_migrations_dir) -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def fxtr_apply_all_migrations(backend, all_migrations): """Apply all the migrations. diff --git a/tests/unit/auth/fixtures/user_fixtures.py b/tests/unit/auth/fixtures/user_fixtures.py index 3242534..dfb37ef 100644 --- a/tests/unit/auth/fixtures/user_fixtures.py +++ b/tests/unit/auth/fixtures/user_fixtures.py @@ -21,7 +21,7 @@ TEST_USERS = ( User(uuid.UUID("60faf8a7-832b-471e-b6a0-bd4013f1fa0e"), "sys@admin.user", "System Admin User", created=_created_)) -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def fxtr_basic_setup(auth_testdb_path, fxtr_apply_all_migrations):# pylint: disable=[redefined-outer-name, unused-argument] admin = User(uuid.UUID("0cb7b0b5-bac4-4359-9ef1-e79c33e5be2a"), "default@system.admin", "Default System Administrator", diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index a43889d..bd9f78e 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -19,7 +19,7 @@ def setup_secrets(rootdir: Path) -> Path: return secretsfile -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def fxtr_startup_configs(): """Get configs before app is created.""" import gn_auth.migrations.auth as migrdir @@ -46,20 +46,20 @@ def fxtr_startup_configs(): testdb.unlink(missing_ok=True) -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def fxtr_app(fxtr_basic_setup, fxtr_startup_configs): """Fixture: setup the test app""" app = create_app(fxtr_startup_configs) app.testing = True return app -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def client(fxtr_app): # pylint: disable=redefined-outer-name """Create a test client fixture for tests""" with fxtr_app.app_context(): yield fxtr_app.test_client() -@pytest.fixture(scope="session") +@pytest.fixture(scope="function") def fxtr_app_config(client): # pylint: disable=redefined-outer-name """Return the test application's configuration object""" return client.application.config |
