Skip to content

Only check for workerid if workerinput is present #274

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

Merged
merged 1 commit into from
Feb 11, 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
138 changes: 76 additions & 62 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ def set_tokenizers_parallelism():
@pytest.fixture(scope="session", autouse=True)
def redis_container(request):
"""
Create a unique Compose project for each xdist worker by setting
COMPOSE_PROJECT_NAME. That prevents collisions on container/volume names.
If using xdist, create a unique Compose project for each xdist worker by
setting COMPOSE_PROJECT_NAME. That prevents collisions on container/volume
names.
"""
# In xdist, the config has "workerid" in workerinput
worker_id = request.config.workerinput.get("workerid", "master")
workerinput = getattr(request.config, "workerinput", {})
worker_id = workerinput.get("workerid", "master")

# Set the Compose project name so containers do not clash across workers
os.environ["COMPOSE_PROJECT_NAME"] = f"redis_test_{worker_id}"
Expand All @@ -45,6 +47,7 @@ def redis_url(redis_container):
host, port = redis_container.get_service_host_and_port("redis", 6379)
return f"redis://{host}:{port}"


@pytest.fixture
async def async_client(redis_url):
"""
Expand All @@ -58,6 +61,7 @@ async def async_client(redis_url):
if "Event loop is closed" not in str(e):
raise


@pytest.fixture
def client(redis_url):
"""
Expand All @@ -67,110 +71,120 @@ def client(redis_url):
yield conn
conn.close()


@pytest.fixture
def openai_key():
return os.getenv("OPENAI_API_KEY")


@pytest.fixture
def openai_version():
return os.getenv("OPENAI_API_VERSION")


@pytest.fixture
def azure_endpoint():
return os.getenv("AZURE_OPENAI_ENDPOINT")


@pytest.fixture
def cohere_key():
return os.getenv("COHERE_API_KEY")


@pytest.fixture
def mistral_key():
return os.getenv("MISTRAL_API_KEY")


@pytest.fixture
def gcp_location():
return os.getenv("GCP_LOCATION")


@pytest.fixture
def gcp_project_id():
return os.getenv("GCP_PROJECT_ID")


@pytest.fixture
def aws_credentials():
return {
"aws_access_key_id": os.getenv("AWS_ACCESS_KEY_ID"),
"aws_secret_access_key": os.getenv("AWS_SECRET_ACCESS_KEY"),
"aws_region": os.getenv("AWS_REGION", "us-east-1")
"aws_region": os.getenv("AWS_REGION", "us-east-1"),
}


@pytest.fixture
def sample_data():
return [
{
"user": "john",
"age": 18,
"job": "engineer",
"credit_score": "high",
"location": "-122.4194,37.7749",
"user_embedding": [0.1, 0.1, 0.5]
},
{
"user": "mary",
"age": 14,
"job": "doctor",
"credit_score": "low",
"location": "-122.4194,37.7749",
"user_embedding": [0.1, 0.1, 0.5]
},
{
"user": "nancy",
"age": 94,
"job": "doctor",
"credit_score": "high",
"location": "-122.4194,37.7749",
"user_embedding": [0.7, 0.1, 0.5]
},
{
"user": "tyler",
"age": 100,
"job": "engineer",
"credit_score": "high",
"location": "-110.0839,37.3861",
"user_embedding": [0.1, 0.4, 0.5]
},
{
"user": "tim",
"age": 12,
"job": "dermatologist",
"credit_score": "high",
"location": "-110.0839,37.3861",
"user_embedding": [0.4, 0.4, 0.5]
},
{
"user": "taimur",
"age": 15,
"job": "CEO",
"credit_score": "low",
"location": "-110.0839,37.3861",
"user_embedding": [0.6, 0.1, 0.5]
},
{
"user": "joe",
"age": 35,
"job": "dentist",
"credit_score": "medium",
"location": "-110.0839,37.3861",
"user_embedding": [0.9, 0.9, 0.1]
},
]
{
"user": "john",
"age": 18,
"job": "engineer",
"credit_score": "high",
"location": "-122.4194,37.7749",
"user_embedding": [0.1, 0.1, 0.5],
},
{
"user": "mary",
"age": 14,
"job": "doctor",
"credit_score": "low",
"location": "-122.4194,37.7749",
"user_embedding": [0.1, 0.1, 0.5],
},
{
"user": "nancy",
"age": 94,
"job": "doctor",
"credit_score": "high",
"location": "-122.4194,37.7749",
"user_embedding": [0.7, 0.1, 0.5],
},
{
"user": "tyler",
"age": 100,
"job": "engineer",
"credit_score": "high",
"location": "-110.0839,37.3861",
"user_embedding": [0.1, 0.4, 0.5],
},
{
"user": "tim",
"age": 12,
"job": "dermatologist",
"credit_score": "high",
"location": "-110.0839,37.3861",
"user_embedding": [0.4, 0.4, 0.5],
},
{
"user": "taimur",
"age": 15,
"job": "CEO",
"credit_score": "low",
"location": "-110.0839,37.3861",
"user_embedding": [0.6, 0.1, 0.5],
},
{
"user": "joe",
"age": 35,
"job": "dentist",
"credit_score": "medium",
"location": "-110.0839,37.3861",
"user_embedding": [0.9, 0.9, 0.1],
},
]


@pytest.fixture
def clear_db(redis):
redis.flushall()
yield
redis.flushall()


@pytest.fixture
def app_name():
return "test_app"