Skip to content

Commit

Permalink
Merge branch 'develop' into fix-favicon_added
Browse files Browse the repository at this point in the history
  • Loading branch information
sharath-1517 authored Nov 26, 2024
2 parents 68525cd + ea79aa9 commit 0baa91d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 110 deletions.
34 changes: 6 additions & 28 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
from db.deprecated.utils import get_pg_catalog_table
from db.deprecated.metadata import get_empty_metadata

from fixtures.utils import create_scoped_fixtures


@pytest.fixture(scope="session")
def engine_cache(request):
import logging
logger = logging.getLogger(f'engine_cache-{request.scope}')
Expand All @@ -40,24 +39,15 @@ def _get(db_name):
logger.debug('exit')


# defines:
# FUN_engine_cache
# CLA_engine_cache
# MOD_engine_cache
# SES_engine_cache
create_scoped_fixtures(globals(), engine_cache)


def create_db(request, SES_engine_cache):
@pytest.fixture(scope="session")
def create_db(request, engine_cache):
"""
A factory for Postgres mathesar-installed databases. A fixture made of this method tears down
created dbs when leaving scope.
This method is used to create fixtures with different scopes, that's why it's not a fixture
itself.
"""
engine_cache = SES_engine_cache

import logging
logger = logging.getLogger(f'create_db-{request.scope}')
logger.debug('enter')
Expand Down Expand Up @@ -89,14 +79,6 @@ def __create_db(db_name):
logger.debug('exit')


# defines:
# FUN_create_db
# CLA_create_db
# MOD_create_db
# SES_create_db
create_scoped_fixtures(globals(), create_db)


@pytest.fixture(scope="session")
def worker_id(worker_id):
"""
Expand Down Expand Up @@ -136,21 +118,19 @@ def uid(get_uid):


@pytest.fixture(scope="session", autouse=True)
def test_db_name(worker_id, SES_create_db):
def test_db_name(worker_id, create_db):
"""
A dynamic, yet non-random, db_name is used so that subsequent runs would automatically clean up
test databases that we failed to tear down.
"""
create_db = SES_create_db
default_test_db_name = "mathesar_db_test"
db_name = f"{default_test_db_name}_{worker_id}"
create_db(db_name)
yield db_name


@pytest.fixture(scope="session")
def engine(test_db_name, SES_engine_cache):
engine_cache = SES_engine_cache
def engine(test_db_name, engine_cache):
engine = engine_cache(test_db_name)
add_custom_types_to_ischema_names(engine)
return engine
Expand All @@ -169,15 +149,13 @@ def engine_with_schema(engine, _test_schema_name, create_db_schema):


@pytest.fixture
def create_db_schema(SES_engine_cache):
def create_db_schema(engine_cache):
"""
Creates a DB schema factory, making sure to track and clean up new instances.
Schema setup and teardown is very fast, so we'll only use this fixture with the default
"function" scope.
"""
engine_cache = SES_engine_cache

import logging
logger = logging.getLogger('create_db_schema')
logger.debug('enter')
Expand Down
69 changes: 0 additions & 69 deletions fixtures/utils.py

This file was deleted.

17 changes: 4 additions & 13 deletions mathesar/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from db import connection
from mathesar.models.users import User

from fixtures.utils import create_scoped_fixtures


@pytest.fixture
def mocked_responses():
Expand Down Expand Up @@ -52,16 +50,17 @@ def enable_db_access_for_all_tests(db):


@pytest.fixture(scope="session", autouse=True)
def ignore_all_dbs_except_default(SES_dj_databases):
def ignore_all_dbs_except_default(dj_databases):
"""
Ignore the default test database: we're creating and tearing down our own databases dynamically.
"""
entry_name_to_keep = "default"
for entry_name in set(SES_dj_databases.keys()):
for entry_name in set(dj_databases.keys()):
if entry_name != entry_name_to_keep:
del SES_dj_databases[entry_name]
del dj_databases[entry_name]


@pytest.fixture(scope="session")
def dj_databases():
"""
Returns django.conf.settings.DATABASES by reference. During cleanup, restores it to the state
Expand All @@ -72,14 +71,6 @@ def dj_databases():
settings.DATABASES = dj_databases_deep_copy


# defines:
# FUN_dj_databases
# CLA_dj_databases
# MOD_dj_databases
# SES_dj_databases
create_scoped_fixtures(globals(), dj_databases)


@pytest.fixture(scope='session')
def patents_csv_filepath():
return 'mathesar/tests/data/patents.csv'
Expand Down

0 comments on commit 0baa91d

Please sign in to comment.