Skip to content

[MAINTENANCE] Assert store access in DatasourceDict just-in-time tests#11949

Open
anxkhn wants to merge 1 commit into
fivetran:developfrom
anxkhn:patch-9
Open

[MAINTENANCE] Assert store access in DatasourceDict just-in-time tests#11949
anxkhn wants to merge 1 commit into
fivetran:developfrom
anxkhn:patch-9

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Two unit tests in tests/datasource/test_datasource_dict.py that are meant to verify DatasourceDict reads its store just-in-time were not asserting anything, so they passed unconditionally and gave no regression protection.

  • test_datasource_dict_data_property_requests_store_just_in_time
  • test_datasource_dict___contains___requests_store_just_in_time

Both wrote:

store.list_keys_count = 0
_ = empty_datasource_dict.data
store.list_keys_count = 1

Lines 100/102 (and 111/113 in the second test) are plain assignments to the spy counter, not assertions, so nothing is ever checked. Every other test in the same file uses the assert store.<counter> == N pattern (for example assert store.set_count == 1).

Root cause

Two problems compound:

  1. = was written where assert ... == was intended, so the tests assert nothing.
  2. The counter is the wrong one. DatasourceDict.data (great_expectations/datasource/datasource_dict.py:71) calls self._datasource_store.get_all(), not list_keys(). DatasourceStoreSpy tracks get/set/list_keys/has_key/remove_key but does not override get_all, so list_keys_count stays 0 on a .data access. Even the naive repair (assert store.list_keys_count == 1) would fail.

The behavior these tests are named for is documented at great_expectations/datasource/datasource_dict.py:63-67:

This is generated just-in-time as the contents of the store may have changed.

Fix

Have the spy track get_all() and assert on it, so both tests become real red -> green guards for just-in-time store access:

  • Add get_all_count to DatasourceStoreSpy (initialized in __init__ and reset alongside the existing counters) and override get_all() to increment it via super().get_all(), matching the file's existing spy-override style.
  • Replace the four assignment lines with assert store.get_all_count == 0 before the .data access and assert store.get_all_count == 1 after.

Testing

  • python -m pytest tests/datasource/test_datasource_dict.py -q -> 13 passed.
  • Red -> green check: temporarily making .data skip the store makes both tests fail with assert 0 == 1; reverting restores green. Before this change they passed against that same breakage.
  • invoke lint --path tests/datasource/test_datasource_dict.py passes (import-sort, ruff format --check, ruff check).

PR checklist (from the repo template)

  • Description of PR changes above includes a link to an existing GitHub issue
    -- see note below; no matching issue exists, and recent test-harness [MAINTENANCE] PRs merged without one.
  • PR title is prefixed with one of: [BUGFIX], [FEATURE], [DOCS], [MAINTENANCE], [CONTRIB], [MINORBUMP]
  • Code is linted - run invoke lint (uses ruff format + ruff check)
  • Appropriate tests and docs have been updated

The two 'requests_store_just_in_time' tests set store.list_keys_count = 0/1
instead of asserting on it, so they asserted nothing and passed even when
DatasourceDict.data never touched the store. The intended counter was also
wrong: .data calls DatasourceStore.get_all(), not list_keys(), which the spy
did not track (list_keys_count stays 0).

Track get_all() in DatasourceStoreSpy and assert store.get_all_count goes
from 0 to 1, turning both tests into real regression guards for just-in-time
store access.
@netlify

netlify Bot commented Jul 5, 2026

Copy link
Copy Markdown

👷 Deploy request for niobium-lead-7998 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7e9133a

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