conftest.py — anthropic-sdk-python Source File
Architecture documentation for conftest.py, a python file in the anthropic-sdk-python codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 68a6e880_ca4a_fcf0_511e_42d9fe42570f["conftest.py"] bb0af148_44a9_df40_49c4_0fa6ceb5a403["os"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> bb0af148_44a9_df40_49c4_0fa6ceb5a403 33e7b7bd_cc48_e59c_0e93_20dce57f27ca["logging"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> 33e7b7bd_cc48_e59c_0e93_20dce57f27ca 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf["httpx"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2 53ab428b_b358_a6ba_b84b_f2ed8e095de0["pytest_asyncio"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> 53ab428b_b358_a6ba_b84b_f2ed8e095de0 d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> d10c5377_2939_0f0b_cc44_8759393f2853 d1009234_f799_7c53_7892_4262523206dd["anthropic._utils"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> d1009234_f799_7c53_7892_4262523206dd 3a5bf07a_bb8d_0c2c_425b_cd9712997b6d["_pytest.fixtures"] 68a6e880_ca4a_fcf0_511e_42d9fe42570f --> 3a5bf07a_bb8d_0c2c_425b_cd9712997b6d style 68a6e880_ca4a_fcf0_511e_42d9fe42570f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
from __future__ import annotations
import os
import logging
from typing import TYPE_CHECKING, Iterator, AsyncIterator
import httpx
import pytest
from pytest_asyncio import is_async_test
from anthropic import Anthropic, AsyncAnthropic, DefaultAioHttpClient
from anthropic._utils import is_dict
if TYPE_CHECKING:
from _pytest.fixtures import FixtureRequest # pyright: ignore[reportPrivateImportUsage]
pytest.register_assert_rewrite("tests.utils")
logging.getLogger("anthropic").setLevel(logging.DEBUG)
# automatically add `pytest.mark.asyncio()` to all of our async tests
# so we don't have to add that boilerplate everywhere
def pytest_collection_modifyitems(items: list[pytest.Function]) -> None:
pytest_asyncio_tests = (item for item in items if is_async_test(item))
session_scope_marker = pytest.mark.asyncio(loop_scope="session")
for async_test in pytest_asyncio_tests:
async_test.add_marker(session_scope_marker, append=False)
# We skip tests that use both the aiohttp client and respx_mock as respx_mock
# doesn't support custom transports.
for item in items:
if "async_client" not in item.fixturenames or "respx_mock" not in item.fixturenames:
continue
if not hasattr(item, "callspec"):
continue
async_client_param = item.callspec.params.get("async_client")
if is_dict(async_client_param) and async_client_param.get("http_client") == "aiohttp":
item.add_marker(pytest.mark.skip(reason="aiohttp client is not compatible with respx_mock"))
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
api_key = "my-anthropic-api-key"
@pytest.fixture(scope="session")
def client(request: FixtureRequest) -> Iterator[Anthropic]:
strict = getattr(request, "param", True)
if not isinstance(strict, bool):
raise TypeError(f"Unexpected fixture parameter type {type(strict)}, expected {bool}")
with Anthropic(base_url=base_url, api_key=api_key, _strict_response_validation=strict) as client:
yield client
@pytest.fixture(scope="session")
async def async_client(request: FixtureRequest) -> AsyncIterator[AsyncAnthropic]:
param = getattr(request, "param", True)
# defaults
strict = True
http_client: None | httpx.AsyncClient = None
if isinstance(param, bool):
strict = param
elif is_dict(param):
strict = param.get("strict", True)
assert isinstance(strict, bool)
http_client_type = param.get("http_client", "httpx")
if http_client_type == "aiohttp":
http_client = DefaultAioHttpClient()
else:
raise TypeError(f"Unexpected fixture parameter type {type(param)}, expected bool or dict")
async with AsyncAnthropic(
base_url=base_url, api_key=api_key, _strict_response_validation=strict, http_client=http_client
) as client:
yield client
Domain
Subdomains
Dependencies
- _pytest.fixtures
- anthropic
- anthropic._utils
- httpx
- logging
- os
- pytest
- pytest_asyncio
- typing
Source
Frequently Asked Questions
What does conftest.py do?
conftest.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, Authentication subdomain.
What functions are defined in conftest.py?
conftest.py defines 4 function(s): _pytest, async_client, client, pytest_collection_modifyitems.
What does conftest.py depend on?
conftest.py imports 9 module(s): _pytest.fixtures, anthropic, anthropic._utils, httpx, logging, os, pytest, pytest_asyncio, and 1 more.
Where is conftest.py in the architecture?
conftest.py is located at tests/conftest.py (domain: AnthropicClient, subdomain: Authentication, directory: tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free