AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
move decorator higher up
Merwane Hamadib7cd56f72b5c
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 069e5633ea..780db14fc6 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -71,8 +71,7 @@ jobs:- name: Run unittest tests with coveragerun: |- pytest --cov=autogpt --without-integration --without-slow-integration --cov-report term-missing --cov-branch --cov-report xml --cov-report term- pytest --cov=autogpt tests/integration/goal_oriented --cov-report term-missing --cov-branch --cov-report xml --cov-report term+ pytest --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report termenv:OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}- name: Generate coverage reportdiff --git a/tests/conftest.py b/tests/conftest.pyindex 36233c18ff..bf6bd6c59f 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -1,5 +1,3 @@from dotenv import load_dotenvload_dotenv()--# Your other pytest configurations and fixturesdiff --git a/tests/integration/goal_oriented/decorators.py b/tests/integration/goal_oriented/decorators.pydeleted file mode 100644index 9f35fc330c..0000000000--- a/tests/integration/goal_oriented/decorators.py+++ /dev/null@@ -1,14 +0,0 @@-import os-import pytest---def requires_openai_api_key(func):- def wrapper(*args, **kwargs):- if not os.environ.get('OPENAI_API_KEY'):- pytest.skip(- "Environment variable 'OPENAI_API_KEY' is not set, skipping the test."- )- else:- return func(*args, **kwargs)-- return wrapperdiff --git a/tests/integration/goal_oriented/test_write_file.py b/tests/integration/goal_oriented/test_write_file.pyindex 55c51f204b..d995c7a39a 100644--- a/tests/integration/goal_oriented/test_write_file.py+++ b/tests/integration/goal_oriented/test_write_file.py@@ -2,7 +2,6 @@ import concurrentimport osimport unittest-import pytestimport vcrfrom autogpt.agent import Agent@@ -13,8 +12,8 @@ from autogpt.memory import get_memory# from autogpt.prompt import Promptfrom autogpt.workspace import WORKSPACE_PATH-from tests.integration.goal_oriented.decorators import requires_openai_api_keyfrom tests.integration.goal_oriented.vcr_helper import before_record_request+from tests.utils import requires_api_keycurrent_file_dir = os.path.dirname(os.path.abspath(__file__))# tests_directory = os.path.join(current_file_dir, 'tests')@@ -28,11 +27,8 @@ my_vcr = vcr.VCR(CFG = Config()-@requires_openai_api_key[email protected]_test+@requires_api_key("OPENAI_API_KEY")def test_write_file() -> None:- # Your test code here-# if file existfile_name = "hello_world.txt"diff --git a/tests/local_cache_test.py b/tests/local_cache_test.pyindex bb10862656..bbaf8e572f 100644--- a/tests/local_cache_test.py+++ b/tests/local_cache_test.py@@ -7,6 +7,7 @@ import unittestimport pytestfrom autogpt.memory.local import LocalCache+from tests.utils import requires_api_keydef mock_config() -> dict:@@ -32,17 +33,20 @@ class TestLocalCache(unittest.TestCase):self.cfg = mock_config()self.cache = LocalCache(self.cfg)+ @requires_api_key("OPENAI_API_KEY")def test_add(self) -> None:"""Test adding a text to the cache"""text = "Sample text"self.cache.add(text)self.assertIn(text, self.cache.data.texts)+ @requires_api_key("OPENAI_API_KEY")def test_clear(self) -> None:"""Test clearing the cache"""self.cache.clear()self.assertEqual(self.cache.data.texts, [])+ @requires_api_key("OPENAI_API_KEY")def test_get(self) -> None:"""Test getting a text from the cache"""text = "Sample text"@@ -50,6 +54,7 @@ class TestLocalCache(unittest.TestCase):result = self.cache.get(text)self.assertEqual(result, [text])+ @requires_api_key("OPENAI_API_KEY")def test_get_relevant(self) -> None:"""Test getting relevant texts from the cache"""text1 = "Sample text 1"@@ -59,6 +64,7 @@ class TestLocalCache(unittest.TestCase):result = self.cache.get_relevant(text1, 1)self.assertEqual(result, [text1])+ @requires_api_key("OPENAI_API_KEY")def test_get_stats(self) -> None:"""Test getting the cache stats"""text = "Sample text"diff --git a/tests/test_image_gen.py b/tests/test_image_gen.pyindex 19c57e427d..58b8337f42 100644--- a/tests/test_image_gen.py+++ b/tests/test_image_gen.py@@ -7,6 +7,7 @@ from PIL import Imagefrom autogpt.commands.image_gen import generate_image, generate_image_with_sd_webuifrom autogpt.config import Configfrom autogpt.workspace import path_in_workspace+from tests.utils import requires_api_keydef lst(txt):@@ -18,6 +19,7 @@ class TestImageGen(unittest.TestCase):def setUp(self):self.config = Config()+ @requires_api_key("OPENAI_API_KEY")def test_dalle(self):self.config.image_provider = "dalle"@@ -36,6 +38,7 @@ class TestImageGen(unittest.TestCase):self.assertEqual(img.size, (512, 512))image_path.unlink()+ @requires_api_key("HUGGINGFACE_API_TOKEN")def test_huggingface(self):self.config.image_provider = "huggingface"diff --git a/tests/utils.py b/tests/utils.pynew file mode 100644index 0000000000..a09daa8dfd--- /dev/null+++ b/tests/utils.py@@ -0,0 +1,18 @@+import os++import pytest+++def requires_api_key(env_var):+ def decorator(func):+ def wrapper(*args, **kwargs):+ if not os.environ.get(env_var):+ pytest.skip(+ f"Environment variable '{env_var}' is not set, skipping the test."+ )+ else:+ return func(*args, **kwargs)++ return wrapper++ return decorator