Skip to content

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Aug 5, 2025

feat: Add --no-creds option to connector and image test commands

Summary

Adds a --no-creds CLI option to both airbyte-cdk connector test and airbyte-cdk image test commands that skips tests marked with the requires_creds pytest marker. This enables running tests without requiring credentials to be configured, which is useful for CI environments, forks, and local development where credentials may not be available.

Key Changes:

  • Added --no-creds flag to airbyte-cdk connector test command
  • Added --no-creds flag to airbyte-cdk image test command
  • When --no-creds is used, tests marked with requires_creds are skipped via pytest marker filtering
  • For connector tests: uses -m "not requires_creds" filter
  • For image tests: combines with existing marker using -m "image_tests and not requires_creds"
  • Maintains full backward compatibility when flag is not used

Review & Testing Checklist for Human

  • Test actual functionality with a real connector that has requires_creds tests - verify that --no-creds properly skips those tests while running others
  • Verify pytest marker syntax is correct, especially the "image_tests and not requires_creds" combination for image tests
  • Test CLI argument handling works correctly with other options like --collect-only and --pytest-arg
  • Confirm backward compatibility by running both commands without --no-creds to ensure existing behavior is unchanged

Recommended Test Plan:

  1. Find a connector with tests marked @pytest.mark.requires_creds
  2. Run airbyte-cdk connector test <connector> --collect-only (should show requires_creds tests)
  3. Run airbyte-cdk connector test <connector> --no-creds --collect-only (should skip requires_creds tests)
  4. Run airbyte-cdk image test <connector> --no-creds --collect-only (should show only image_tests that don't require creds)

Diagram

%%{ init : { "theme" : "default" }}%%
graph TB
    CLI1["airbyte_cdk/cli/airbyte_cdk/<br/>_connector.py"]:::major-edit
    CLI2["airbyte_cdk/cli/airbyte_cdk/<br/>_image.py"]:::major-edit
    
    SHARED["airbyte_cdk/cli/airbyte_cdk/<br/>_connector.py<br/>run_connector_tests()"]:::context
    
    PYTEST_INI["pytest.ini<br/>requires_creds marker"]:::context
    PYPROJECT["pyproject.toml<br/>existing pattern"]:::context
    
    CLI1 -->|"calls with<br/>extra_pytest_args"| SHARED
    CLI2 -->|"calls with<br/>extra_pytest_args"| SHARED
    
    CLI1 -.->|"adds -m not requires_creds<br/>when --no-creds used"| PYTEST_INI
    CLI2 -.->|"adds -m image_tests and<br/>not requires_creds"| PYTEST_INI
    
    PYPROJECT -.->|"existing pattern:<br/>pytest-fast excludes<br/>requires_creds"| PYTEST_INI

    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit  
        L3[Context/No Edit]:::context
    end

    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#F5F5F5
Loading

Notes

  • Implementation follows the existing pattern used in pyproject.toml where pytest-fast already excludes requires_creds tests
  • The requires_creds marker is already defined in pytest.ini
  • Both commands leverage the shared run_connector_tests() function, so the implementation is consistent
  • Limited local testing was possible since the commands require being run from a proper connector directory

Link to Devin session: https://app.devin.ai/sessions/9fc0a40482c64cbc8c865fb7f009f415
Requested by: @aaronsteers

Summary by CodeRabbit

  • New Features
    • Added a new --no-creds command-line option to both the connector and image test commands, allowing users to easily skip tests that require credentials.
    • Test scenarios now automatically identify and mark those requiring credentials, improving test selection and execution.

- Add --no-creds flag to airbyte-cdk connector test command
- Add --no-creds flag to airbyte-cdk image test command
- Skip tests marked with 'requires_creds' when --no-creds is used
- For connector test: use '-m not requires_creds' filter
- For image test: combine with existing marker using 'image_tests and not requires_creds'
- Maintains backward compatibility when flag is not used

Co-Authored-By: AJ Steers <[email protected]>
@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 17:44
@github-actions github-actions bot added the enhancement New feature or request label Aug 5, 2025
Copy link

github-actions bot commented Aug 5, 2025

👋 Greetings, Airbyte Team Member!

Here are some helpful tips and reminders for your convenience.

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@devin/1754415435-add-no-creds-option#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 devin/1754415435-add-no-creds-option

Helpful Resources

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
  • /poe <command> - Runs any poe command in the CDK environment

📝 Edit this welcome message.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a --no-creds CLI option to both airbyte-cdk connector test and airbyte-cdk image test commands, allowing users to skip tests that require credentials. This is useful for CI environments, forks, and local development where credentials may not be available.

  • Added --no-creds flag to both connector and image test commands
  • Implemented pytest marker filtering to skip tests marked with requires_creds
  • Maintained backward compatibility when the flag is not used

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
airbyte_cdk/cli/airbyte_cdk/_connector.py Added --no-creds option and logic to filter out requires_creds tests
airbyte_cdk/cli/airbyte_cdk/_image.py Added --no-creds option and modified marker filter to exclude requires_creds tests

Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

A new --no-creds boolean flag was introduced to both the connector_test and image_test CLI commands. When enabled, this flag modifies test execution to skip tests marked with requires_creds by altering the pytest marker expressions accordingly. The commands' signatures and argument construction logic were updated to support this feature. Additionally, a requires_creds property was added to ConnectorTestScenario to identify credential-requiring tests, and the test parametrization logic was enhanced to mark such scenarios for pytest filtering.

Changes

Cohort / File(s) Change Summary
Connector CLI Test Command
airbyte_cdk/cli/airbyte_cdk/_connector.py
Added --no-creds flag to connector_test command; updates pytest args to skip credential-requiring tests.
Image CLI Test Command
airbyte_cdk/cli/airbyte_cdk/_image.py
Added --no-creds flag to image_test command; updates pytest marker expression to exclude credential-requiring tests.
Test Scenario Model
airbyte_cdk/test/models/scenario.py
Added requires_creds property to ConnectorTestScenario to detect if a scenario needs credentials based on its config path.
Pytest Hooks for Scenario Parameterization
airbyte_cdk/test/standard_tests/pytest_hooks.py
Modified pytest_generate_tests to parametrize scenarios with conditional requires_creds pytest marks for selective test running.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Pytest

    User->>CLI: Run test command with or without --no-creds
    CLI->>CLI: Check if --no-creds is set
    alt --no-creds is set
        CLI->>Pytest: Run tests excluding "requires_creds" markers
    else --no-creds not set
        CLI->>Pytest: Run all tests (including those requiring creds)
    end
    Pytest-->>CLI: Test results
    CLI-->>User: Display results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Suggested labels

testing, ci

Suggested reviewers

  • dbgold17

By the way, would you like me to help draft an example usage snippet for the new --no-creds flag to include in your CLI documentation, wdyt?

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1754415435-add-no-creds-option

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
airbyte_cdk/cli/airbyte_cdk/_image.py (1)

113-113: Solid implementation with a slightly different approach!

The logic correctly filters out credential-requiring tests when the flag is enabled. I notice this uses a ternary operator to modify the marker expression directly ("image_tests and not requires_creds"), while the connector implementation uses extend(["-m", "not requires_creds"]). Both approaches work correctly - wdyt about keeping them consistent, or is the inline approach preferable here since you're already constructing the marker expression?

Also applies to: 134-134

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f976c72 and f227297.

📒 Files selected for processing (2)
  • airbyte_cdk/cli/airbyte_cdk/_connector.py (2 hunks)
  • airbyte_cdk/cli/airbyte_cdk/_image.py (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: the files in `airbyte_cdk/cli/source_declarative_manifest/`, including `_run.py`, are imported from ...
Learnt from: aaronsteers
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/cli/source_declarative_manifest/_run.py:62-65
Timestamp: 2024-11-15T01:04:21.272Z
Learning: The files in `airbyte_cdk/cli/source_declarative_manifest/`, including `_run.py`, are imported from another repository, and changes to these files should be minimized or avoided when possible to maintain consistency.

Applied to files:

  • airbyte_cdk/cli/airbyte_cdk/_connector.py
  • airbyte_cdk/cli/airbyte_cdk/_image.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Check: source-pokeapi
  • GitHub Check: Check: source-intercom
  • GitHub Check: Check: source-shopify
  • GitHub Check: Check: destination-motherduck
  • GitHub Check: Check: source-hardcoded-records
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: SDM Docker Image Build
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
airbyte_cdk/cli/airbyte_cdk/_connector.py (2)

126-131: Nice implementation of the --no-creds flag!

The CLI option follows established click patterns and has clear, descriptive help text. The default value ensures backward compatibility. LGTM!


137-137: Clean implementation of the credential filtering logic!

The function signature update and pytest marker filtering logic look great. Using extend(["-m", "not requires_creds"]) correctly excludes tests marked with the requires_creds marker when the flag is enabled. The implementation maintains backward compatibility and follows established patterns in the codebase.

Also applies to: 157-158

airbyte_cdk/cli/airbyte_cdk/_image.py (1)

103-108: Consistent CLI option implementation!

The --no-creds flag definition matches the implementation in _connector.py, which provides a consistent user experience across both commands. Nice work maintaining consistency!

Copy link

github-actions bot commented Aug 5, 2025

PyTest Results (Fast)

3 695 tests  ±0   3 684 ✅ ±0   6m 25s ⏱️ -10s
    1 suites ±0      11 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 23ee94b. ± Comparison against base commit f976c72.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Aug 5, 2025

PyTest Results (Full)

3 698 tests  ±0   3 687 ✅ ±0   11m 44s ⏱️ +11s
    1 suites ±0      11 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 23ee94b. ± Comparison against base commit f976c72.

♻️ This comment has been updated with latest results.

@aaronsteers aaronsteers requested a review from dbgold17 August 5, 2025 19:49
@aaronsteers aaronsteers marked this pull request as draft August 5, 2025 19:57
@aaronsteers
Copy link
Contributor Author

Note: I still need to plumb the requires_creds marks into the pytest classes and methods.

Copy link
Contributor

Manual Testing Results for Dynamic requires_creds Implementation

Overview

Successfully tested the dynamic requires_creds marker implementation that automatically detects credential requirements based on config file paths containing "secrets/".

Test Environment

  • CDK Branch: devin/1754415435-add-no-creds-option
  • Python: 3.10.16
  • Pytest: 7.4.4

Test Cases

Test Case 1: source-microsoft-lists (Manifest-Only Connector)

Command: poetry run airbyte-cdk connector test source-microsoft-lists --collect-only
Result: ✅ SUCCESS - 8 tests collected

Command: poetry run airbyte-cdk connector test source-microsoft-lists --no-creds --collect-only
Result: ✅ SUCCESS - 2 tests collected, 6 deselected

Analysis:

  • Tests using secrets/config.json were automatically marked with requires_creds
  • The --no-creds flag correctly filtered out credential-requiring tests
  • Only tests that don't require credentials (like test_spec) remained

Test Case 2: source-intercom (Manifest-Only Connector)

Command: poetry run airbyte-cdk connector test source-intercom --collect-only
Result: ✅ SUCCESS - 20 tests collected

Command: poetry run airbyte-cdk connector test source-intercom --no-creds --collect-only
Result: ✅ SUCCESS - 8 tests collected, 12 deselected

Analysis:

  • Tests using secrets/config.json and secrets/config_sandbox.json were automatically marked
  • Tests using integration_tests/invalid_config.json were NOT marked (correctly)
  • The dynamic detection correctly identified which scenarios require credentials

Key Findings

✅ Dynamic Detection Working

The requires_creds property correctly identifies scenarios based on path patterns:

@property
def requires_creds(self) -> bool:
    """Return True if the scenario requires credentials to run."""
    return bool(self.config_path and "secrets" in self.config_path.parts)

✅ Automatic Marker Application

The pytest hooks correctly apply markers dynamically:

parametrized_scenarios = [
    pytest.param(
        scenario,
        marks=[pytest.mark.requires_creds] if scenario.requires_creds else [],
    )
    for scenario in scenarios
]

✅ CLI Integration Working

Both CLI commands correctly filter tests:

  • airbyte-cdk connector test --no-creds uses -m "not requires_creds"
  • airbyte-cdk image test --no-creds uses -m "image_tests and not requires_creds"

Verification Summary

Connector Total Tests Tests with --no-creds Filtered Out Status
source-microsoft-lists 8 2 6 ✅ PASS
source-intercom 20 8 12 ✅ PASS

Conclusion

The dynamic requires_creds implementation is working correctly:

  1. Automatic Detection: No manual marking needed - scenarios automatically get markers based on config paths
  2. Granular Control: Each scenario gets its own marker based on its specific config path
  3. Perfect Integration: Works seamlessly with existing --no-creds CLI options
  4. Path-Based Logic: Correctly identifies secrets/ paths as requiring credentials

The implementation eliminates the need for manual test marking while providing accurate, scenario-specific credential detection.

@aaronsteers aaronsteers marked this pull request as ready for review August 5, 2025 21:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
airbyte_cdk/test/standard_tests/pytest_hooks.py (1)

164-170: Update error message to reflect the method requirement, wdyt?

The error message still references the 'scenarios' attribute, but the code now requires a 'get_scenarios' method. Should we update this for clarity?

-                f"Test class {test_class} does not have a 'scenarios' attribute. "
-                "Please define the 'scenarios' attribute in the test class."
+                f"Test class {test_class} does not have a 'get_scenarios' method. "
+                "Please define the 'get_scenarios' method in the test class."
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3aa52e and 23ee94b.

📒 Files selected for processing (2)
  • airbyte_cdk/test/models/scenario.py (1 hunks)
  • airbyte_cdk/test/standard_tests/pytest_hooks.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • airbyte_cdk/test/models/scenario.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: when modifying the `yamldeclarativesource` class in `airbyte_cdk/sources/declarative/yaml_declarativ...
Learnt from: ChristoGrab
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the `YamlDeclarativeSource` class in `airbyte_cdk/sources/declarative/yaml_declarative_source.py`, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.

Applied to files:

  • airbyte_cdk/test/standard_tests/pytest_hooks.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Check: source-shopify
🔇 Additional comments (1)
airbyte_cdk/test/standard_tests/pytest_hooks.py (1)

175-189: Nice implementation of conditional marker application!

The logic for wrapping scenarios in pytest.param objects with conditional requires_creds markers looks solid and aligns perfectly with the PR objectives. This approach enables the --no-creds CLI option to filter out credential-requiring tests effectively.

Copy link
Contributor

@dbgold17 dbgold17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronsteers thanks for doing this!

@aaronsteers aaronsteers merged commit e849b98 into main Aug 5, 2025
26 of 27 checks passed
@aaronsteers aaronsteers deleted the devin/1754415435-add-no-creds-option branch August 5, 2025 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants