Files
Auto-GPT/tests/utils.py
merwanehamadi 02f546d2bc 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>
2023-04-26 20:45:03 -05:00

43 lines
1019 B
Python

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) and env_var == "OPENAI_API_KEY":
with dummy_openai_api_key():
return func(*args, **kwargs)
else:
return func(*args, **kwargs)
return wrapper
return decorator
def skip_in_ci(test_function):
return pytest.mark.skipif(
os.environ.get("CI") == "true",
reason="This test doesn't work on GitHub Actions.",
)(test_function)