Skip to content

test: stop pook mocks leaking between REST test classes - #9

Draft
chipkent wants to merge 1 commit into
masterfrom
test/pook-mock-leak
Draft

chipkent wants to merge 1 commit into
masterfrom
test/pook-mock-leak

Conversation

@chipkent

@chipkent chipkent commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Preview only. This is a draft in the fork showing the exact text of the PR planned for massive-com/client-python. It will be closed, not merged, once the upstream PR is opened.

Fixes #<issue: POOK-MOCK-LEAK>

BaseTest turns pook on and registers its mocks in setUpClass, but never turns pook off. Every class's mocks stay active for the rest of the run.

That hides a bug in two tests. Each sends the same request twice, and each mock answers once, so the second request is answered by a mock left over from an earlier class. Run alone on master, both fail:

$ cd test_rest
$ python -m unittest test_dividends
ERROR: test_list_stocks_dividends_ticker_any_of (test_dividends.DividendsTest.test_list_stocks_dividends_ticker_any_of)
pook.exceptions.PookNoMatches: pook error!
$ python -m unittest test_snapshots
ERROR: test_get_snapshot_indices (test_snapshots.SnapshotsTest.test_get_snapshot_indices)
pook.exceptions.PookNoMatches: pook error!
  • BaseTest.tearDownClass calls pook.off(), which stops interception and drops the class's mocks.
  • A test class can list mocks that must answer more than once in persistent_mocks; those are registered with persist=True. The two tests above use it.
  • All other mocks still answer once. The pagination tests rely on that, because a first-page mock also matches the request for the next page.

Tests only; the package does not change.

Tests

  • test_dividends and test_snapshots pass when run on their own.
  • make test and make lint pass on 3.10 and 3.14.

BaseTest turned pook on and registered its mocks in setUpClass but never
turned pook off, so every class's mocks stayed active for the rest of the
run.

That hid a problem in two tests. test_list_stocks_dividends_ticker_any_of
and test_get_snapshot_indices each send the same request twice, but each
mock answers only once. Their second request was answered by a copy that
an earlier class had registered, so both fail with PookNoMatches when
their module runs on its own.

Turn pook off in tearDownClass. Let a test class name the mocks that must
answer more than once, and register those with persist. Other mocks still
answer once, because the pagination tests rely on it: a first-page mock
also matches the request for the next page.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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.

1 participant