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

Skip tests that depend on OpenAI via --skip-openai #1097

Merged
merged 11 commits into from
Dec 31, 2023
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,15 @@ jobs:
pip install -e .
python -c "import autogen"
pip install -e. pytest mock
pip uninstall -y openai
- name: Test with pytest
if: matrix.python-version != '3.10'
run: |
pytest test
pytest test --skip-openai
- name: Coverage
if: matrix.python-version == '3.10'
run: |
pip install -e .[test]
pip uninstall -y openai
coverage run -a -m pytest test --ignore=test/agentchat/contrib
coverage run -a -m pytest test --ignore=test/agentchat/contrib --skip-openai
coverage xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.10'
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,7 @@ test/my_tmp/*

# Storage for the AgentEval output
test/test_files/agenteval-in-out/out/

# Files created by tests
*tmp_code_*
test/agentchat/test_agent_scripts/*
23 changes: 12 additions & 11 deletions test/agentchat/contrib/test_agent_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from packaging.requirements import Requirement
from autogen.agentchat.contrib.agent_builder import AgentBuilder
from autogen import UserProxyAgent
from conftest import skip_openai

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
Expand All @@ -20,15 +21,15 @@
from openai.types.completion import Completion
from openai.types.completion_usage import CompletionUsage
import diskcache

OPENAI_INSTALLED = True
except ImportError:
OPENAI_INSTALLED = False
skip = True
else:
skip = False or skip_openai


@pytest.mark.skipif(
not OPENAI_INSTALLED,
reason="do not run when dependency is not installed",
skip,
reason="openai not installed OR requested to skip",
)
def test_build():
builder = AgentBuilder(config_path=oai_config_path, builder_model="gpt-4", agent_model="gpt-4")
Expand Down Expand Up @@ -57,8 +58,8 @@ def test_build():


@pytest.mark.skipif(
not OPENAI_INSTALLED,
reason="do not run when dependency is not installed",
skip,
reason="openai not installed OR requested to skip",
)
def test_save():
builder = AgentBuilder(config_path=oai_config_path, builder_model="gpt-4", agent_model="gpt-4")
Expand Down Expand Up @@ -93,8 +94,8 @@ def test_save():


@pytest.mark.skipif(
not OPENAI_INSTALLED,
reason="do not run when dependency is not installed",
skip,
reason="openai not installed OR requested to skip",
)
def test_load():
builder = AgentBuilder(config_path=oai_config_path, builder_model="gpt-4", agent_model="gpt-4")
Expand Down Expand Up @@ -128,8 +129,8 @@ def test_load():


@pytest.mark.skipif(
not OPENAI_INSTALLED,
reason="do not run when dependency is not installed",
skip,
reason="openai not installed OR requested to skip",
)
def test_clear_agent():
builder = AgentBuilder(config_path=oai_config_path, builder_model="gpt-4", agent_model="gpt-4")
Expand Down
23 changes: 14 additions & 9 deletions test/agentchat/contrib/test_compressible_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import autogen
import os
from conftest import skip_openai
from autogen.agentchat.contrib.compressible_agent import CompressibleAgent

here = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -19,15 +20,15 @@

try:
import openai

OPENAI_INSTALLED = True
except ImportError:
OPENAI_INSTALLED = False
skip = True
else:
skip = False or skip_openai


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or not OPENAI_INSTALLED,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_mode_compress():
conversations = {}
Expand Down Expand Up @@ -65,8 +66,8 @@ def test_mode_compress():


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or not OPENAI_INSTALLED,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_mode_customized():
try:
Expand Down Expand Up @@ -135,8 +136,8 @@ def constrain_num_messages(messages):


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or not OPENAI_INSTALLED,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_compress_message():
assistant = CompressibleAgent(
Expand Down Expand Up @@ -169,6 +170,10 @@ def test_compress_message():
assert is_success, "Compression failed."


@pytest.mark.skipif(
skip,
reason="do not run if dependency is not installed OR requested to skip",
)
def test_mode_terminate():
assistant = CompressibleAgent(
name="assistant",
Expand Down
35 changes: 18 additions & 17 deletions test/agentchat/contrib/test_gpt_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import autogen
from autogen import OpenAIWrapper
from conftest import skip_openai

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST # noqa: E402
Expand All @@ -11,10 +12,10 @@
import openai
from autogen.agentchat.contrib.gpt_assistant_agent import GPTAssistantAgent
from autogen.oai.openai_utils import retrieve_assistants_by_name

skip_test = False
except ImportError:
skip_test = True
skip = True
else:
skip = False or skip_openai

config_list = autogen.config_list_from_json(
OAI_CONFIG_LIST, file_location=KEY_LOC, filter_dict={"api_type": ["openai"]}
Expand All @@ -26,8 +27,8 @@ def ask_ossinsight(question):


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or skip_test,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_gpt_assistant_chat():
ossinsight_api_schema = {
Expand Down Expand Up @@ -73,8 +74,8 @@ def test_gpt_assistant_chat():


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or skip_test,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_get_assistant_instructions():
"""
Expand All @@ -97,8 +98,8 @@ def test_get_assistant_instructions():


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or skip_test,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_gpt_assistant_instructions_overwrite():
"""
Expand Down Expand Up @@ -142,8 +143,8 @@ def test_gpt_assistant_instructions_overwrite():


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or skip_test,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_gpt_assistant_existing_no_instructions():
"""
Expand Down Expand Up @@ -178,8 +179,8 @@ def test_gpt_assistant_existing_no_instructions():


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or skip_test,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_get_assistant_files():
"""
Expand Down Expand Up @@ -212,8 +213,8 @@ def test_get_assistant_files():


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or skip_test,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_assistant_retrieval():
"""
Expand Down Expand Up @@ -283,8 +284,8 @@ def test_assistant_retrieval():


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"] or skip_test,
reason="do not run on MacOS or windows or dependency is not installed",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR dependency is not installed OR requested to skip",
)
def test_assistant_mismatch_retrieval():
"""Test function to check if the GPTAssistantAgent can filter out the mismatch assistant"""
Expand Down
3 changes: 2 additions & 1 deletion test/agentchat/contrib/test_teachable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
from autogen import ConversableAgent, config_list_from_json
from conftest import skip_openai

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from test_assistant_agent import OAI_CONFIG_LIST, KEY_LOC # noqa: E402
Expand All @@ -12,7 +13,7 @@
except ImportError:
skip = True
else:
skip = False
skip = False or skip_openai

try:
from termcolor import colored
Expand Down
34 changes: 13 additions & 21 deletions test/agentchat/test_assistant_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
import sys
import pytest
import autogen
from conftest import skip_openai
from autogen.agentchat import AssistantAgent, UserProxyAgent

try:
from openai import OpenAI
except ImportError:
skip = True
else:
skip = False or skip_openai

KEY_LOC = "notebook"
OAI_CONFIG_LIST = "OAI_CONFIG_LIST"
here = os.path.abspath(os.path.dirname(__file__))


@pytest.mark.skipif(
sys.platform in ["darwin", "win32"],
reason="do not run on MacOS or windows",
sys.platform in ["darwin", "win32"] or skip,
reason="do not run on MacOS or windows OR openai not installed OR requested to skip",
)
def test_ai_user_proxy_agent():
try:
import openai
except ImportError:
return

conversations = {}
# autogen.ChatCompletion.start_logging(conversations)

Expand Down Expand Up @@ -57,11 +60,8 @@ def test_ai_user_proxy_agent():
print(conversations)


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
def test_gpt35(human_input_mode="NEVER", max_consecutive_auto_reply=5):
try:
import openai
except ImportError:
return
config_list = autogen.config_list_from_json(
OAI_CONFIG_LIST,
file_location=KEY_LOC,
Expand Down Expand Up @@ -115,12 +115,8 @@ def test_gpt35(human_input_mode="NEVER", max_consecutive_auto_reply=5):
assert not isinstance(user.use_docker, bool) # None or str


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
def test_create_execute_script(human_input_mode="NEVER", max_consecutive_auto_reply=10):
try:
import openai
except ImportError:
return

config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, file_location=KEY_LOC)
conversations = {}
# autogen.ChatCompletion.start_logging(conversations)
Expand Down Expand Up @@ -160,12 +156,8 @@ def test_create_execute_script(human_input_mode="NEVER", max_consecutive_auto_re
# autogen.ChatCompletion.stop_logging()


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
def test_tsp(human_input_mode="NEVER", max_consecutive_auto_reply=10):
try:
import openai
except ImportError:
return

config_list = autogen.config_list_from_json(
OAI_CONFIG_LIST,
file_location=KEY_LOC,
Expand Down
19 changes: 10 additions & 9 deletions test/agentchat/test_async.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import pytest
import asyncio
import autogen
from conftest import skip_openai
from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST

try:
from openai import OpenAI
except ImportError:
skip = True
else:
skip = False or skip_openai


def get_market_news(ind, ind_upper):
data = {
Expand Down Expand Up @@ -45,13 +53,9 @@ def get_market_news(ind, ind_upper):
return feeds_summary


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
@pytest.mark.asyncio
async def test_async_groupchat():
try:
import openai
except ImportError:
return

config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, KEY_LOC)

llm_config = {
Expand Down Expand Up @@ -91,12 +95,9 @@ async def test_async_groupchat():
assert len(user_proxy.chat_messages) > 0


@pytest.mark.skipif(skip, reason="openai not installed OR requested to skip")
@pytest.mark.asyncio
async def test_stream():
try:
import openai
except ImportError:
return
config_list = autogen.config_list_from_json(OAI_CONFIG_LIST, KEY_LOC)
data = asyncio.Future()

Expand Down
Loading
Loading