Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactor LLM tests to use parameterized fixtures with dynamic marking #521

@rjambrecic

Description

@rjambrecic

Refactor LLM tests to remove duplicate test definitions by parameterizing credentials and leveraging dynamic fixture injection while preserving marker-based filtering with pytest -m.

# Define test cases with the necessary parameters
all_llm_fixture_credentials = [
    pytest.param(
        "credentials_gpt_4o", 
        marks=pytest.mark.openai
    ),
    pytest.param(
        "credentials_gemini_pro", 
        marks=pytest.mark.gemini
    ),
    pytest.param(
        "credentials_anthropic_claude_sonnet", 
        marks=pytest.mark.anthropic
    ),
]

@pytest.mark.parametrize("credentials_fixture", all_llm_fixture_credentials)
def test_groupchat_logging(credentials_fixture, request, db_connection):
    # Retrieve the credentials dynamically using `request.getfixturevalue`
    credentials = request.getfixturevalue(credentials_fixture)
    _test_groupchat_logging(credentials, credentials, db_connection)

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions