Skip to content
Open
Show file tree
Hide file tree
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
74 changes: 74 additions & 0 deletions tests/credential/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2025, Oracle and/or its affiliates.
#
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
# -----------------------------------------------------------------------------

import os

import pytest
import select_ai


def get_credential_env_value(name, default_value=None):
return os.environ.get(f"PYSAI_TEST_{name}", default_value)


@pytest.fixture(scope="session")
def oci_credential():
"""
Override the root autouse OCI credential fixture for credential-only tests.
These suites should not require OCI environment variables unless a test
explicitly opts into them.
"""
return None


@pytest.fixture(scope="session")
def credential_test_params(test_env):
return {
"user": test_env.test_user,
"password": test_env.test_user_password,
"dsn": test_env.connect_string,
"user_ocid": get_credential_env_value(
"OCI_USER_OCID", default_value="user ocid"
),
"tenancy_ocid": get_credential_env_value(
"OCI_TENANCY_OCID", default_value="tenancy ocid"
),
"private_key": get_credential_env_value(
"OCI_PRIVATE_KEY", default_value="private key"
),
"fingerprint": get_credential_env_value(
"OCI_FINGERPRINT", default_value="fingerprint"
),
"cred_username": get_credential_env_value(
"CRED_USERNAME", default_value="OCI credential username"
),
"cred_password": get_credential_env_value(
"CRED_PASSWORD", default_value="OCI credential password"
),
}


@pytest.fixture(scope="session")
def credential_connect_as(test_env):
def _connect_as(admin=False, **overrides):
select_ai.disconnect()
Copy link
Copy Markdown
Member

@aosingh aosingh May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't run select_ai.disconnect() in individual conftest.

We have seen this causes issues as it modifies the global connection state. We already have connect/disconnect in the root level conftest.py which is automatically run for every module.

https://github.com/oracle/python-select-ai/blob/main/tests/conftest.py#L201

We should not do any connection management in individual test suites.

connect_params = test_env.connect_params(admin=admin)
connect_params.update(overrides)
select_ai.connect(**connect_params)

return _connect_as


@pytest.fixture(scope="session")
def credential_async_connect_as(test_env):
async def _connect_as(admin=False, **overrides):
await select_ai.async_disconnect()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have async connect and disconnect here
https://github.com/oracle/python-select-ai/blob/main/tests/conftest.py#L208

No need to connect here

connect_params = test_env.connect_params(admin=admin)
connect_params.update(overrides)
await select_ai.async_connect(**connect_params)

return _connect_as
Loading
Loading