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:
merwanehamadi
2023-04-26 18:45:03 -07:00
committed by GitHub
parent 3b56716a68
commit 02f546d2bc
13 changed files with 897 additions and 84 deletions

View File

@@ -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)