test: standardize SDK-boundary mocking on pytest-mock#47
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adopt pytest-mock and route all test mocking through the
mockerfixture, replacing the parallel use of
unittest.mock(patch/MagicMock)that ran alongside pytest's monkeypatch.
unittest.mockimports are nowgone from the test suite.
SDK-boundary patches (the
client.*/ams.*wrapper functions and theassemblyai SDK classes) now use
autospec=True, so calls are validatedagainst 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.