Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO-REF: Fix CI tests when unable to connect to DB #545

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

TEST_SOURCE = 'test_source'


def pytest_addoption(parser):
parser.addoption('--env', action='store', default='local', help='Environment to use for tests')

Expand All @@ -23,18 +24,31 @@ def setup_env(pytestconfig, request):

running_unit_tests = any('unit' in item.keywords for item in request.session.items)

if not running_unit_tests and environment in ['local', 'qa']:
if not running_unit_tests and environment in ['local', 'local-qa', 'qa']:
load_env_file(environment, file_string=f'config/{environment}.yaml')

@pytest.fixture(scope='module')
def db_manager():
db_manager = DBManager()
db_manager.createSession()
yield db_manager
db_manager.close_connection()

try:
db_manager.createSession()

yield db_manager

db_manager.close_connection()
except:
yield None


@pytest.fixture(scope='module')
def seed_test_data(db_manager):
# TODO: find path forward to connect to db in GH actions
if db_manager is None:
return {
'edition_id': 1982731
}

flags = { 'catalog': False, 'download': False, 'reader': False, 'embed': True }
test_data = {
'title': 'test data 1',
Expand Down Expand Up @@ -83,14 +97,18 @@ def seed_test_data(db_manager):
'uuid': str(test_data['uuid'])
}


@pytest.fixture(scope='module')
def seeded_edition_id(request, seed_test_data):
if 'functional' in request.keywords or 'integration' in request.keywords:
return seed_test_data['edition_id']

return None


@pytest.fixture(scope='module')
def seeded_uuid(request, seed_test_data):
if 'functional' in request.keywords or 'integration' in request.keywords:
return seed_test_data['uuid']

return None
Loading