Skip to content

Commit

Permalink
Use skip_on_missing_imports to mark tests in test/agentchat files
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl committed Jan 23, 2025
1 parent d909c93 commit 4d69c68
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 39 deletions.
22 changes: 6 additions & 16 deletions test/agentchat/test_cache_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,13 @@
import autogen
from autogen.agentchat import AssistantAgent, UserProxyAgent
from autogen.cache import Cache
from autogen.import_utils import optional_import_block
from autogen.import_utils import skip_on_missing_imports

from ..conftest import Credentials

with optional_import_block() as result:
from openai import OpenAI # noqa: F401

skip_tests = not result.is_successful

with optional_import_block() as result:
import redis # noqa: F401

skip_redis_tests = not result.is_successful


@pytest.mark.openai
@pytest.mark.skipif(skip_tests, reason="openai not installed")
@skip_on_missing_imports(["openai"])
def test_legacy_disk_cache(credentials_gpt_4o_mini: Credentials):
random_cache_seed = int.from_bytes(os.urandom(2), "big")
start_time = time.time()
Expand Down Expand Up @@ -83,29 +73,29 @@ def _test_redis_cache(credentials: Credentials):

@pytest.mark.openai
@pytest.mark.redis
@pytest.mark.skipif(skip_tests or skip_redis_tests, reason="redis not installed OR openai not installed")
@skip_on_missing_imports(["openai", "redis"], "redis")
def test_redis_cache(credentials_gpt_4o_mini: Credentials):
_test_redis_cache(credentials_gpt_4o_mini)


@pytest.mark.skip(reason="Currently not working")
@pytest.mark.gemini
@pytest.mark.redis
@pytest.mark.skipif(skip_tests or skip_redis_tests, reason="redis not installed OR openai not installed")
@skip_on_missing_imports(["openai", "redis"], "redis")
def test_redis_cache_gemini(credentials_gemini_pro: Credentials):
_test_redis_cache(credentials_gemini_pro)


@pytest.mark.skip(reason="Currently not working")
@pytest.mark.anthropic
@pytest.mark.redis
@pytest.mark.skipif(skip_tests or skip_redis_tests, reason="redis not installed OR openai not installed")
@skip_on_missing_imports(["openai", "redis"], "redis")
def test_redis_cache_anthropic(credentials_anthropic_claude_sonnet: Credentials):
_test_redis_cache(credentials_anthropic_claude_sonnet)


@pytest.mark.openai
@pytest.mark.skipif(skip_tests, reason="openai not installed")
@skip_on_missing_imports(["openai"])
def test_disk_cache(credentials_gpt_4o_mini: Credentials):
random_cache_seed = int.from_bytes(os.urandom(2), "big")
start_time = time.time()
Expand Down
12 changes: 4 additions & 8 deletions test/agentchat/test_function_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@
import pytest

import autogen
from autogen.import_utils import optional_import_block
from autogen.import_utils import skip_on_missing_imports
from autogen.math_utils import eval_math_responses

from ..conftest import Credentials, reason

with optional_import_block() as result:
from openai import OpenAI # noqa: F401

skip = not result.is_successful


@pytest.mark.openai
@pytest.mark.skipif(skip, reason=reason)
@skip_on_missing_imports(["openai"])
def test_eval_math_responses(credentials_gpt_4o_mini: Credentials):
functions = [
{
Expand Down Expand Up @@ -220,9 +215,10 @@ def get_number():

@pytest.mark.openai
@pytest.mark.skipif(
skip or not sys.version.startswith("3.10"),
not sys.version.startswith("3.10"),
reason=reason,
)
@skip_on_missing_imports(["openai"])
def test_update_function(credentials_gpt_4o_mini: Credentials):
llm_config = {
"config_list": credentials_gpt_4o_mini.config_list,
Expand Down
8 changes: 2 additions & 6 deletions test/agentchat/test_math_user_proxy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
_add_print_to_last_line,
_remove_print,
)
from autogen.import_utils import optional_import_block
from autogen.import_utils import skip_on_missing_imports

from ..conftest import Credentials

with optional_import_block() as result:
from openai import OpenAI # noqa: F401

skip = not result.is_successful


@pytest.mark.openai
@skip_on_missing_imports(["openai"])
def test_math_user_proxy_agent(
credentials_gpt_4o_mini: Credentials,
):
Expand Down
16 changes: 7 additions & 9 deletions test/agentchat/test_tool_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,16 @@
import pytest

import autogen
from autogen.import_utils import optional_import_block
from autogen.import_utils import skip_on_missing_imports
from autogen.math_utils import eval_math_responses
from autogen.oai.client import TOOL_ENABLED

from ..conftest import Credentials

with optional_import_block() as result:
from openai import OpenAI # noqa: F401

skip = not result.is_successful


@pytest.mark.openai
@pytest.mark.skipif(skip or not TOOL_ENABLED, reason="openai>=1.1.0 not installed or requested to skip")
@pytest.mark.skipif(not TOOL_ENABLED, reason="openai>=1.1.0 not installed or requested to skip")
@skip_on_missing_imports(["openai"])
def test_eval_math_responses(credentials_gpt_4o_mini: Credentials):
config_list = credentials_gpt_4o_mini.config_list
tools = [
Expand Down Expand Up @@ -80,7 +76,8 @@ def test_eval_math_responses(credentials_gpt_4o_mini: Credentials):


@pytest.mark.openai
@pytest.mark.skipif(skip or not TOOL_ENABLED, reason="openai>=1.1.0 not installed or requested to skip")
@pytest.mark.skipif(not TOOL_ENABLED, reason="openai>=1.1.0 not installed or requested to skip")
@skip_on_missing_imports(["openai"])
def test_eval_math_responses_api_style_function(credentials_gpt_4o_mini: Credentials):
config_list = credentials_gpt_4o_mini.config_list
functions = [
Expand Down Expand Up @@ -131,9 +128,10 @@ def test_eval_math_responses_api_style_function(credentials_gpt_4o_mini: Credent

@pytest.mark.openai
@pytest.mark.skipif(
skip or not TOOL_ENABLED or not sys.version.startswith("3.10"),
not TOOL_ENABLED or not sys.version.startswith("3.10"),
reason="do not run if openai is <1.1.0 or py!=3.10 or requested to skip",
)
@skip_on_missing_imports(["openai"])
def test_update_tool(credentials_gpt_4o: Credentials):
llm_config = {
"config_list": credentials_gpt_4o.config_list,
Expand Down

0 comments on commit 4d69c68

Please sign in to comment.