Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(airbyte-ci): Enable manifest-only connector unit tests in CI #48790

Merged
merged 23 commits into from
Dec 12, 2024

Conversation

ChristoGrab
Copy link
Contributor

@ChristoGrab ChristoGrab commented Dec 3, 2024

What

Enables unit testing capabilities for manifest-only connectors and validates the approach using source-the-guardian-api as a proof of concept. This change allows manifest-only connectors to maintain test coverage of custom components while benefiting from the simplified manifest-based architecture.

Demo: https://www.loom.com/share/80b3ae7282e94dd0acfa34854b877462?sid=18b54fd6-79e0-4154-83ba-462d4345ddcb

Note

The changes in this PR are reliant on the availability of the test fixtures in the CDK. The PR to include those fixtures can be found here: airbytehq/airbyte-python-cdk#121

How

Guardian API PoC:

  • Implemented unit tests for the source's CustomPageIncrement component
  • Set the base_image version to a release candidate of the CDK containing the fixtures needed to dynamically load components.py

airbyte-ci

  • Modified airbyte-ci to support running unit tests for manifest-only connectors:
  • Added ManifestConnectorUnitTests class inheriting from PytestStep
  • Enabled unit test execution during CI

This approach provides a bridge for maintaining test coverage as we transition connectors to the manifest-only format, ensuring we can continue to maintain existing unit tests for custom Python components.

How to Test

  1. Pull this branch locally and navigate to the airbyte-integrations/connectors/source-the-guardian-api/unit_tests folder
  2. Run poetry install and poetry run pytest to verify the tests run locally.
  3. Navigate to airbyte-ci/connectors/pipelines and run poetry install and poetry shell
  4. Run airbyte-ci connectors --name=source-the-guardian-api test --only-step=unit to run just the unit test suite against a built connector image.
  5. The results of the full test run can also be verified in the CI checks for this PR.

Can this PR be safely reverted and rolled back?

  • YES 💚
  • NO ❌

Copy link

vercel bot commented Dec 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
airbyte-docs ⬜️ Ignored (Inspect) Visit Preview Dec 12, 2024 0:21am

@octavia-squidington-iii octavia-squidington-iii added the area/documentation Improvements or additions to documentation label Dec 4, 2024
@ChristoGrab ChristoGrab marked this pull request as ready for review December 5, 2024 00:16
@ChristoGrab ChristoGrab requested a review from a team December 5, 2024 00:16
@octavia-squidington-iv octavia-squidington-iv requested a review from a team December 5, 2024 00:17
[tool.poetry.dependencies]
python = "^3.10"
airbyte-cdk = "5.17.0"
pytest = "^8"
Copy link
Contributor Author

@ChristoGrab ChristoGrab Dec 5, 2024

Choose a reason for hiding this comment

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

Two things to note:

  1. I opted out of dev dependencies as the whole project is just a testing harness and I don't believe there is any need for separation of main/dev deps.
  2. For this iteration, the CDK version will have to be manually matched to whatever is listed in the connector's metadata. It should be a small pull to add some logic to up-to-date that automatically does this for us.

def test_page_increment(components_module, current_page, total_pages, expected_next_page):
"""Test the CustomPageIncrement pagination for various page combinations"""

CustomPageIncrement = components_module.CustomPageIncrement
Copy link
Contributor Author

@ChristoGrab ChristoGrab Dec 5, 2024

Choose a reason for hiding this comment

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

Just highlighting that this is how we can reference individual components within test files

Copy link
Contributor

@bnchrch bnchrch left a comment

Choose a reason for hiding this comment

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

Great work. Just had a few questions. Nothing that should be blocking though

@octavia-squidington-iv octavia-squidington-iv requested a review from a team December 5, 2024 15:14
@ChristoGrab
Copy link
Contributor Author

ChristoGrab commented Dec 9, 2024

/format-fix

Format-fix job started... Check job output.

✅ Changes applied successfully. (77ef2a4)

@ChristoGrab ChristoGrab requested a review from bnchrch December 10, 2024 00:37
],
ids=["First page", "Middle page", "Penultimate page", "Last page", "Single page"]
)
def test_page_increment(connector_dir, components_module, current_page, total_pages, expected_next_page):
Copy link
Contributor

Choose a reason for hiding this comment

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

@ChristoGrab I see something sus.

Since you import components_module at the top and reference it as an argument.

Which is it using?

What happens if you remove the argument version?

Suggested change
def test_page_increment(connector_dir, components_module, current_page, total_pages, expected_next_page):
def test_page_increment(connector_dir, current_page, total_pages, expected_next_page):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to using the plugin approach and it works without the import statement 🎉

import airbyte_cdk
import pytest
import requests
from airbyte_cdk.test.utils.manifest_only_fixtures import components_module, connector_dir
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Why do we have to import?

Should this not be a pytest plugin that adds the fixture as an option for any test?

e.g.

# conftest.py
pytest_plugins = ["airbyte_cdk.test_fixtures"]
# some_unit_test.py
def test_ connector_dir(connector_dir):
    assert connector_dir.exists()

Copy link
Contributor Author

@ChristoGrab ChristoGrab Dec 10, 2024

Choose a reason for hiding this comment

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

Yup, this approach seems to work and allows us to remove the import 👍 Should see the results in CI soon

@ChristoGrab
Copy link
Contributor Author

ChristoGrab commented Dec 10, 2024

/format-fix

Format-fix job started... Check job output.

✅ Changes applied successfully. (9098198)

@ChristoGrab ChristoGrab requested a review from bnchrch December 10, 2024 22:28
Copy link
Contributor

@bnchrch bnchrch left a comment

Choose a reason for hiding this comment

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

Well done, well implemented

@ChristoGrab ChristoGrab enabled auto-merge (squash) December 12, 2024 00:41
@ChristoGrab ChristoGrab changed the title PoC: Enable manifest-only connector unit tests feat(airbyte-ci): Enable manifest-only connector unit tests in CI Dec 12, 2024
@ChristoGrab ChristoGrab merged commit 3b3c965 into master Dec 12, 2024
38 checks passed
@ChristoGrab ChristoGrab deleted the christo/sdm-unit-test-poc branch December 12, 2024 00:43
Copy link

sentry-io bot commented Dec 12, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ FileNotFoundError: Could not find pyproject.toml in the unit_tests directory for source-trello. pipelines.airbyte_ci.connectors.test.steps.mani... View Issue

Did you find this useful? React with a 👍 or 👎

barduinor pushed a commit to box-community/airbyte that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation connectors/source/the-guardian-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants