Skip to content

Commit

Permalink
Automate token management for local tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chadell committed Oct 30, 2023
1 parent 6094f3f commit 86f8154
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 0 additions & 7 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ def tests(context, local=INVOKE_LOCAL):
context (obj): Used to run specific commands
local (bool): Define as `True` to execute locally
"""
token_openai = os.getenv("OPENAI_TOKEN")
if token_openai:
del os.environ["OPENAI_TOKEN"]

black(context, local)
flake8(context, local)
pylint(context, local)
Expand All @@ -275,7 +271,4 @@ def tests(context, local=INVOKE_LOCAL):
mypy(context, local)
pytest(context, local)

if token_openai:
os.environ["OPENAI_TOKEN"] = token_openai

print("All tests have passed!")
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Bootstrap Pytest."""
import os


token_openai = os.getenv("OPENAI_TOKEN")


def pytest_configure(config): # pylint: disable=unused-argument
"""Clean environment for tests."""
if token_openai:
del os.environ["OPENAI_TOKEN"]


def pytest_sessionfinish(session, exitstatus): # pylint: disable=unused-argument
"""Recove environment after tests."""
if token_openai:
os.environ["OPENAI_TOKEN"] = token_openai

0 comments on commit 86f8154

Please sign in to comment.