Skip to content

test: standardize SDK-boundary mocking on pytest-mock#47

Merged
alexkroman merged 5 commits into
mainfrom
claude/adoring-hawking-ao77al
Jun 9, 2026
Merged

test: standardize SDK-boundary mocking on pytest-mock#47
alexkroman merged 5 commits into
mainfrom
claude/adoring-hawking-ao77al

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Adopt pytest-mock and route all test mocking through the mocker
fixture, replacing the parallel use of unittest.mock (patch/MagicMock)
that ran alongside pytest's monkeypatch. unittest.mock imports are now
gone from the test suite.

SDK-boundary patches (the client.*/ams.* wrapper functions and the
assemblyai SDK classes) now use autospec=True, so calls are validated
against the real signatures instead of silently accepting any call shape.
Env/config isolation and the existing module-attribute stubs stay on
monkeypatch, unchanged.

Class/classmethod patches that fight autospec's self/cls binding, and the
whole-module stubs in the init-template tests (which can't be autospec'd),
are converted to mocker without autospec.

claude added 5 commits June 9, 2026 04:54
Adopt pytest-mock and route all test mocking through the `mocker`
fixture, replacing the parallel use of `unittest.mock` (patch/MagicMock)
that ran alongside pytest's monkeypatch. `unittest.mock` imports are now
gone from the test suite.

SDK-boundary patches (the `client.*`/`ams.*` wrapper functions and the
assemblyai SDK classes) now use `autospec=True`, so calls are validated
against the real signatures instead of silently accepting any call shape.
Env/config isolation and the existing module-attribute stubs stay on
monkeypatch, unchanged.

Class/classmethod patches that fight autospec's self/cls binding, and the
whole-module stubs in the init-template tests (which can't be autospec'd),
are converted to mocker without autospec.
Randomizes test order (and seeds RNG) each run, so inter-test state
leakage surfaces instead of hiding behind a fixed collection order —
relevant here given the process-global active environment and the
module-level mutable state in the streaming/template tests.

Verified the full default suite passes under multiple seeds with no
order-dependence; coverage and snapshot gates are order-independent and
unaffected.
Wire `-n auto` into the check.sh pytest stage, halving the suite wall
time (~42s -> ~21s with coverage). Safe because the suite is now
order-independent (pytest-randomly), and verified that pytest-cov's
per-worker combine preserves the per-test --cov-context=test contexts
the diff-scoped mutation gate depends on.
Add focused tests for previously-uncovered branches so the patch-coverage
gate (diff-cover vs origin/main) reaches 100%:

- agent._resolve_system_prompt: the OSError -> CLIError path when an
  unreadable --system-prompt-file is given (agent.py).
- audit._format_action: the direct known-key match that skips
  normalization (audit.py).
- run_session: the `connect is None` default branch that lazily imports
  websockets' sync client (agent/session.py), patched so no real socket
  is opened.
…g-ao77al

# Conflicts:
#	tests/test_login.py
#	tests/test_transcribe.py
@alexkroman alexkroman merged commit 9a679d9 into main Jun 9, 2026
11 checks passed
@alexkroman alexkroman deleted the claude/adoring-hawking-ao77al branch June 9, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants