- Framework: pytest, with pytest-asyncio, pytest-httpx, pytest-mock, freezegun (versions in
pyproject.tomldev group) - Location:
tests/, grouped by area (test_api_client.py,test_cache.py,test_utils.py,test_act.py,test_token_store.py,test_telemetry.py), not one file per source module - Coverage: pytest-cov.
pyproject.tomladdoptsalways applies--cov=src --cov-report=term-missing:skip-covered --cov-report=xml. No minimum threshold is configured.
The default poetry run pytest suite needs no credentials. All Auth0 HTTP calls go through httpx_mock. Fixtures use https://auth0.local, and test_api_client.py also uses tenant1.auth0.com.
poetry run pytest # all unit tests
poetry run pytest tests/test_cache.py # one file
poetry run pytest tests/test_api_client.py -k dpop # filter by name- Module-level
test_<subject>_<condition>functions (e.g.test_verify_access_token_fail_no_iss), often with a one-line docstring, grouped under# ===== Section =====comment banners in every file excepttest_act.py. No test classes. - Async tests are marked explicitly with
@pytest.mark.asyncio. Noasyncio_modeis configured, so an unmarkedasync def test_...will not run as intended. - Assert error types with
pytest.raises(VerifyAccessTokenError)and similar. Where both exist, assert onget_error_code()/.codeandget_status_code()rather than message text. Codes are the contract. Messages are not. - Test placeholders stay obviously synthetic (
cid,csecret,auth0.local). Never paste a real tenant value. - Time-dependent tests use
@freeze_time(...)from freezegun. Cache TTL tests intest_cache.pyuse short real sleeps.
tests/conftest.pyprovides:api_client_confidential: anApiClientwithdomain="auth0.local", placeholderclient_id/client_secret, and anInMemoryTokenStore, so OBO and Token Vault calls verify the token and cacheapi_client_confidential_no_store: the same client without atoken_store, for exchanges that must not verify or cacheInMemoryTokenStore,InMemoryIndexedTokenStore: test-only stores (never for production), the latter forscope_matching="non_strict"mock_discovery: registers the discovery responsemock_token_response(...),token_success(...),last_form(...),last_auth_header(...): token endpoint mocking and request inspectionunsigned_jwt(header, payload): a JWT-shaped string from any JSON values with a dummy signature, for malformed header and payload testsassert_api_error(...),assert_http_basic_auth(...),assert_form_post(...),assert_no_requests(...): shared assertions. Useassert_api_errorrather than hand-rolling.code/ status checksauth0_client_payload(request),assert_telemetry_headers(request, name=...): decode theAuth0-Clientheader of a recorded request, and assert it andUser-Agentare present. Use these for any test of requests sent to Auth0
src/auth0_api_python/token_utils.pyprovidesgenerate_token,generate_dpop_proof,generate_token_with_cnf, signed with a synthetic test key. Use these instead of hand-building JWTs.- Use the constants
DISCOVERY_URL,JWKS_URL,TOKEN_ENDPOINTfromconftest.pyrather than repeating URLs.