pytest-clerk-mock
A pytest plugin for mocking Clerk auth plus the supported Clerk backend SDK clients.
Supported SDK surfaces:
usersorganizationsorganization_memberships
The plugin patches Clerk at the SDK level, so it works even if your app instantiates its Clerk client before the test runs.
Installation
pip install pytest-clerk-mock
Or with Poetry:
poetry add --group dev pytest-clerk-mock
Quick Start
def test_create_user(mock_clerk):
user = mock_clerk.users.create(
email_address=["test@example.com"],
first_name="John",
last_name="Doe",
)
fetched = mock_clerk.users.get(user_id=user.id)
assert fetched.email_addresses[0].email_address == "test@example.com"
Async methods use Clerk-style signatures too:
async def test_create_user_async(mock_clerk):
user = await mock_clerk.users.create_async(email_address=["test@example.com"])
fetched = await mock_clerk.users.get_async(user_id=user.id)
assert fetched.id == user.id
Auth Helpers
def test_auth(mock_clerk, request, options):
mock_clerk.configure_auth("user_123", org_id="org_456", org_role="org:admin")
result = mock_clerk.authenticate_request(request, options)
assert result.is_signed_in
Temporary auth context:
with mock_clerk.as_user("user_456", org_id="org_789"):
...
Predefined users:
MockClerkUser.TEAM_OWNERMockClerkUser.TEAM_MEMBERMockClerkUser.GUESTMockClerkUser.UNAUTHENTICATED
Common Examples
Organizations:
created = mock_clerk.organizations.create(
request={
"name": "My Organization",
"created_by": "user_123",
"slug": "my-org",
}
)
org = mock_clerk.organizations.get(organization_id=created.id)
Organization memberships:
membership = mock_clerk.organization_memberships.create(
organization_id="org_123",
user_id="user_123",
role="org:admin",
)
If your app reads memberships through users.get_organization_memberships(...), seed them explicitly:
from pytest_clerk_mock import MockOrganizationMembershipsResponse
mock_clerk.users.set_organization_memberships(
"user_123",
MockOrganizationMembershipsResponse(data=[], total_count=0),
)
Scope
This package aims for strong parity for the supported Clerk SDK surfaces above. It does not try to mock every Clerk API domain.
The contract tests and CI job are the source of truth for supported method and model parity.
Test Helpers
Useful non-SDK helpers:
mock_clerk.users.set_organization_memberships(...)mock_clerk.organizations.add(...)mock_clerk.organization_memberships.get(...)
Custom fixture:
from pytest_clerk_mock import create_mock_clerk_fixture
mock_clerk = create_mock_clerk_fixture(
default_user_id="user_custom",
default_org_id="org_custom",
default_org_role="org:member",
autouse=True,
)
Context manager:
from pytest_clerk_mock import mock_clerk_backend
with mock_clerk_backend(default_user_id="user_123") as mock:
mock.configure_auth("user_456")
Low-level patch helpers:
from pytest_clerk_mock import (
create_clerk_errors,
mock_clerk_user_creation,
mock_clerk_user_creation_failure,
mock_clerk_user_exists,
)
License
MIT
Metadata
Release files for pytest-clerk-mock 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytest_clerk_mock-0.5.0.tar.gz | 22.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_clerk_mock-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.3 kB
Release files / pytest_clerk_mock-0.5.0.tar.gz
| Download URL | pytest_clerk_mock-0.5.0.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dbd63f941b213e29150a96c9b50d87f384bfa2099151cd6fc73a29d590c57b4e
|
|
BLAKE2b-256 checksum How to use checksums |
feaab4e2ed774106cbe3fdd39a419af65d054ad13056934b70169cca7ebf754b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 6, 2026.
Transparency logRelease files / pytest_clerk_mock-0.5.0-py3-none-any.whl
| Download URL | pytest_clerk_mock-0.5.0-py3-none-any.whl |
|---|---|
| Size | 29.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7b67e27bdca6a7864887b00a2a2fc6718baef4ef09f75b83756e525ac239bab
|
|
BLAKE2b-256 checksum How to use checksums |
1a9c1aec4171b2a1feacd36e8be6359898a59f6f51dc429d39a638987c6691f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 6, 2026.
Transparency logSecurity for pytest-clerk-mock 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pytest_clerk_mock-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.