Skip to content

chore: fix pytest warnings from dataclasses starting with Test#477

Merged
Aaron ("AJ") Steers (aaronsteers) merged 13 commits intomainfrom
devin/1744436819-cherry-pick-test-fixes
Apr 15, 2025
Merged

chore: fix pytest warnings from dataclasses starting with Test#477
Aaron ("AJ") Steers (aaronsteers) merged 13 commits intomainfrom
devin/1744436819-cherry-pick-test-fixes

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Apr 12, 2025

Preface from AJ (Aaron ("AJ") Steers (@aaronsteers))

This is a spinoff of cherry-picked improvements from:

It resolves many of the warnings from pytest (see below) that I ran into when working on that PR. They look like this: PytestCollectionWarning: cannot collect test class 'TestLimits' because it has a __init__ constructor

This happens because pytest interprets classes that start with the word Test as a pytest test class. The resolution is to declare __test__ = false in the class definition, which signals to Pytest that the class is not a test class.

Apart from resolving warnings and making more explicit, this is intended to be a no-op.

fix: dataclasses constructor and pytest warnings

Cherry-picked fixes from PR #349 (#349).

This PR contains only the commits marked 'cherry-pick-me' from the original PR, which fix dataclasses constructor issues and pytest warnings.

Pytest warnings being fixed

This PR resolves the following pytest warnings that occur when collecting tests:

/home/ubuntu/repos/airbyte-python-cdk/airbyte_cdk/connector_builder/connector_builder_handler.py:38: PytestCollectionWarning: cannot collect test class 'TestLimits' because it has a __init__ constructor (from: unit_tests/connector_builder/test_connector_builder_handler.py)
/home/ubuntu/repos/airbyte-python-cdk/airbyte_cdk/connector_builder/test_reader/reader.py:38: PytestCollectionWarning: cannot collect test class 'TestReader' because it has a __init__ constructor (from: unit_tests/connector_builder/test_message_grouper.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/declarative/test_yaml_declarative_source.py:135: PytestCollectionWarning: cannot collect test class 'TestFileContent' because it has a __init__ constructor (from: unit_tests/sources/declarative/test_yaml_declarative_source.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/declarative/decoders/test_composite_decoder.py:261: PytestCollectionWarning: cannot collect test class 'TestServer' because it has a __init__ constructor (from: unit_tests/sources/declarative/decoders/test_composite_decoder.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/declarative/parsers/testing_components.py:34: PytestCollectionWarning: cannot collect test class 'TestingCustomSubstreamPartitionRouter' because it has a __init__ constructor (from: unit_tests/sources/declarative/parsers/test_model_to_component_factory.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/declarative/parsers/testing_components.py:18: PytestCollectionWarning: cannot collect test class 'TestingSomeComponent' because it has a __init__ constructor (from: unit_tests/sources/declarative/parsers/test_model_to_component_factory.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/file_based/scenarios/scenario_builder.py:44: PytestCollectionWarning: cannot collect test class 'TestScenario' because it has a __init__ constructor (from: unit_tests/sources/file_based/test_file_based_scenarios.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/file_based/test_file_based_stream_reader.py:64: PytestCollectionWarning: cannot collect test class 'TestStreamReader' because it has a __init__ constructor (from: unit_tests/sources/file_based/test_file_based_stream_reader.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/file_based/test_file_based_stream_reader.py:102: PytestCollectionWarning: cannot collect test class 'TestSpec' because it has a __init__ constructor (from: unit_tests/sources/file_based/test_file_based_stream_reader.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/file_based/scenarios/scenario_builder.py:44: PytestCollectionWarning: cannot collect test class 'TestScenario' because it has a __init__ constructor (from: unit_tests/sources/file_based/test_scenarios.py)
/home/ubuntu/repos/airbyte-python-cdk/unit_tests/sources/file_based/scenarios/scenario_builder.py:44: PytestCollectionWarning: cannot collect test class 'TestScenario' because it has a __init__ constructor (from: unit_tests/sources/streams/concurrent/scenarios/test_concurrent_scenarios.py)

The fix sets __test__ = False on dataclasses that start with "Test" but aren't meant to be collected as test classes by pytest. This prevents pytest from attempting to collect these utility classes as test classes, which fails because they have __init__ constructors.

Link to Devin run: https://app.devin.ai/sessions/6873cfdb3cac4db2826146028138260c
Requested by: Aaron ("AJ") Steers (aj@airbyte.io)

@devin-ai-integration
Copy link
Contributor Author

Original prompt from Aaron:

@Devin - Create a spin-off pr from this one: <https://github.com/airbytehq/airbyte-python-cdk/pull/349/files#diff-028df7a284a9b03a471679c4bf0777c9b8266e048af5be958ed27ca76aced304>

Just create a PR against main with the commits marked 'cherry-pick-me'

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions github-actions bot added bug Something isn't working security labels Apr 12, 2025
@aaronsteers Aaron ("AJ") Steers (aaronsteers) changed the title fix: dataclasses constructor and pytest warnings chore: dataclasses constructor and pytest warnings Apr 12, 2025
@aaronsteers Aaron ("AJ") Steers (aaronsteers) changed the title chore: dataclasses constructor and pytest warnings chore: fix dataclasses constructor and pytest warnings Apr 12, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, but this is my spinoff. ✅
Would love another pair of eyes.

@aaronsteers Aaron ("AJ") Steers (aaronsteers) changed the title chore: fix dataclasses constructor and pytest warnings chore: fix pytest warnings, use kwonly args for Test* dataclasses Apr 12, 2025
Co-Authored-By: Aaron <AJ> Steers <aj@airbyte.io>
@github-actions github-actions bot added the chore label Apr 12, 2025
aaronsteers

This comment was marked as outdated.

devin-ai-integration bot and others added 5 commits April 12, 2025 23:30
Co-Authored-By: Aaron <AJ> Steers <aj@airbyte.io>
Co-Authored-By: Aaron <AJ> Steers <aj@airbyte.io>
Co-Authored-By: Aaron <AJ> Steers <aj@airbyte.io>
Co-Authored-By: Aaron <AJ> Steers <aj@airbyte.io>
@aaronsteers Aaron ("AJ") Steers (aaronsteers) changed the title chore: fix pytest warnings, use kwonly args for Test* dataclasses chore: fix pytest warnings from dataclasses starting with Test Apr 14, 2025
Copy link

Choose a reason for hiding this comment

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

These changes make sense to me, and it looks like we only need to customize this behavior for the specific classes concerned, so the default Pytest behavior will still apply everyone else.

LGTM.

@aaronsteers Aaron ("AJ") Steers (aaronsteers) merged commit a42ad33 into main Apr 15, 2025
25 checks passed
@aaronsteers Aaron ("AJ") Steers (aaronsteers) deleted the devin/1744436819-cherry-pick-test-fixes branch April 15, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working chore security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments