Skip to content

tests: fix flaky JWT and config-migration unit tests - #1243

Merged
Anatolii Yatsuk (tolik0) merged 1 commit into
mainfrom
tolik0/fix-flaky-unit-tests
Oct 21, 2026
Merged

Anatolii Yatsuk (tolik0) merged 1 commit into
mainfrom
tolik0/fix-flaky-unit-tests

Conversation

@tolik0

Copy link
Copy Markdown
Contributor

What

Fixes two unit-test flakes that fail unrelated PRs (for example #1232):

  • JWT tests (unit_tests/sources/declarative/auth/test_jwt.py): test_get_signed_token, test_get_request_options and test_get_request_headers now run under freezegun.freeze_time, as test_get_jwt_payload already does.
  • Config-migration fixtures (migration_mocks in test_manifest_declarative_source.py and test_concurrent_declarative_source.py): open and print are now patched only in the module under test, not in builtins.

Why

  • The JWT tests build the expected token with a second call to _get_jwt_payload(). When a second boundary falls between that call and the authenticator's own call, iat, nbf and exp differ and the tokens don't match. This failed test_get_request_options[test_get_request_headers1] on Python 3.11 and test_get_signed_token on Python 3.12 in the same run.
  • Patching builtins.open catches every open call in the process during the test. In CI, ddtrace read /proc/self/cgroup and wrote a .pyc cache file through the mock, so assert_called_once_with("/fake/config/path", "w") failed with Expected 'open' to be called once. Called 6 times.

Verification

  • poetry run pytest unit_tests/sources/declarative/auth/test_jwt.py unit_tests/legacy/sources/declarative/test_manifest_declarative_source.py unit_tests/sources/declarative/test_concurrent_declarative_source.py -k "jwt or Jwt or migrat": 27 passed.
  • ruff format and ruff check are clean.
  • Test-only change; no runtime code is touched.

🤖 Generated with Claude Code

JWT tests built the expected token in a second call to _get_jwt_payload(),
so a second boundary between the two calls changed iat/exp/nbf. Freeze time.

The config-migration fixtures patched builtins.open and builtins.print, so
any other code opening a file during the test (ddtrace writing .pyc caches)
broke assert_called_once_with. Patch them only in the module under test.
@tolik0
Anatolii Yatsuk (tolik0) requested a review from a team as a code owner October 21, 2026 15:29
@github-actions

Copy link
Copy Markdown

👋 Greetings, Airbyte Team Member!

Here are some helpful tips and reminders for your convenience.

💡 Show Tips and Tricks

Testing This CDK Version

You can test this version of the CDK using the following:

# Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@tolik0/fix-flaky-unit-tests#egg=airbyte-python-cdk[dev]' --help

# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch tolik0/fix-flaky-unit-tests

PR Slash Commands

Airbyte Maintainers can execute the following slash commands on your PR:

  • /autofix - Fixes most formatting and linting issues
  • /poetry-lock - Updates poetry.lock file
  • /test - Runs connector tests with the updated CDK
  • /prerelease - Triggers a prerelease publish with default arguments
  • /poe build - Regenerate git-committed build artifacts, such as the pydantic models which are generated from the manifest JSON schema in YAML.
  • /poe <command> - Runs any poe command in the CDK environment
📚 Show Repo Guidance

Helpful Resources

📝 Edit this welcome message.

@github-actions

Copy link
Copy Markdown

PyTest Results (Fast)

5 838 tests  ±0   5 807 ✅ ±0   9m 45s ⏱️ + 1m 36s
    1 suites ±0      31 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 0598f91. ± Comparison against base commit 8b721cd.

@github-actions

Copy link
Copy Markdown

PyTest Results (Full)

5 841 tests  ±0   5 810 ✅ ±0   16m 18s ⏱️ -23s
    1 suites ±0      31 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 0598f91. ± Comparison against base commit 8b721cd.

@tolik0 Anatolii Yatsuk (tolik0) changed the title test: fix flaky JWT and config-migration unit tests tests: fix flaky JWT and config-migration unit tests Oct 21, 2026
@tolik0
Anatolii Yatsuk (tolik0) merged commit 693f39a into main Oct 21, 2026
25 of 26 checks passed
@tolik0
Anatolii Yatsuk (tolik0) deleted the tolik0/fix-flaky-unit-tests branch October 21, 2026 16:05
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