mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-20 23:44:19 +01:00
Run the integration tests in the CI pipeline BUT without API keys (#3359)
* integration tests in ci pipeline * Update CONTRIBUTING.md Co-authored-by: Reinier van der Leer <github@pwuts.nl> --------- Co-authored-by: Reinier van der Leer <github@pwuts.nl>
This commit is contained in:
@@ -1,17 +1,32 @@
|
||||
import functools
|
||||
import os
|
||||
from contextlib import contextmanager
|
||||
|
||||
import pytest
|
||||
|
||||
from autogpt.config import Config
|
||||
|
||||
|
||||
@contextmanager
|
||||
def dummy_openai_api_key():
|
||||
# even when we record the VCR cassettes, openAI wants an API key
|
||||
config = Config()
|
||||
original_api_key = config.openai_api_key
|
||||
config.set_openai_api_key("sk-dummy")
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
config.set_openai_api_key(original_api_key)
|
||||
|
||||
|
||||
def requires_api_key(env_var):
|
||||
def decorator(func):
|
||||
@functools.wraps(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."
|
||||
)
|
||||
if not os.environ.get(env_var) and env_var == "OPENAI_API_KEY":
|
||||
with dummy_openai_api_key():
|
||||
return func(*args, **kwargs)
|
||||
else:
|
||||
return func(*args, **kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user