-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
45 lines (30 loc) · 1.47 KB
/
conftest.py
File metadata and controls
45 lines (30 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import pytest
from _pytest.runner import runtestprotocol
def pytest_sessionstart(session: pytest.Session) -> None:
_ = session
if os.getenv("NIGHTHAWK_RUN_INTEGRATION_TESTS") == "1":
has_openai = bool(os.getenv("OPENAI_API_KEY"))
has_anthropic = bool(os.getenv("ANTHROPIC_AUTH_TOKEN"))
if not has_openai and not has_anthropic:
raise RuntimeError(
"Integration tests require provider credentials. Set OPENAI_API_KEY for OpenAI integration tests and/or ANTHROPIC_AUTH_TOKEN (and ANTHROPIC_BASE_URL if applicable) for Claude Agent SDK integration tests."
)
def _is_integration_test_item(item: pytest.Item) -> bool:
item_path = getattr(item, "path", None)
if item_path is None:
return False
normalized_path = str(item_path).replace("\\", "/")
return "/tests/integration/" in normalized_path
def pytest_runtest_protocol(item: pytest.Item, nextitem: pytest.Item | None) -> object | None:
if os.getenv("NIGHTHAWK_RUN_INTEGRATION_TESTS") != "1":
return None
if not _is_integration_test_item(item):
return None
item_hook = item.ihook
item_hook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
reports = runtestprotocol(item, log=False, nextitem=nextitem)
for report in reports:
item_hook.pytest_runtest_logreport(report=report)
item_hook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
return True