Skip to content

chore: Add type checking to test/tracing/, test/marshal/, and test/testing/#10913

Merged
bogdankostic merged 7 commits intodeepset-ai:mainfrom
Krishnachaitanyakc:chore/add-type-checking-tracing-marshal-testing-tests
Mar 27, 2026
Merged

chore: Add type checking to test/tracing/, test/marshal/, and test/testing/#10913
bogdankostic merged 7 commits intodeepset-ai:mainfrom
Krishnachaitanyakc:chore/add-type-checking-tracing-marshal-testing-tests

Conversation

@Krishnachaitanyakc
Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Follow up to #10409 and #10428.

This PR extends mypy type checking coverage to three additional test directories: test/tracing/, test/marshal/, and test/testing/.

Changes made:

  • pyproject.toml: Added test/marshal/, test/testing/, and test/tracing/ to the mypy types script target
  • test/tracing/test_logging_tracer.py: Added pytest import, type annotations for caplog parameters (pytest.LogCaptureFixture), return type annotations for component run methods, and # type: ignore[attr-defined] for dynamically-added LogRecord attributes
  • test/tracing/test_datadog.py: Added assert current_span is not None to narrow Span | None type before attribute access
  • test/tracing/test_opentelemetry.py: Same None narrowing for current_span()
  • test/tracing/test_tracer.py: Added Iterator import, fixed generator fixture return type (None -> Iterator[None]), added None narrowing for current_span() before calling raw_span()
  • test/testing/test_factory.py: Changed assert store.delete_documents([]) is None to store.delete_documents([]) since the method is typed to return None

How did you test it?

  • hatch run test:types -- 333 source files, 0 errors
  • hatch run fmt -- all checks passed
  • hatch run test:unit -- test/tracing/ test/testing/ test/marshal/ -- 75 tests passed

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

…sting/

Partially addresses deepset-ai#10396 by extending mypy type checking to three more
test directories. Fixes type errors including missing annotations on
pytest fixtures, unhandled Optional returns from current_span(), incorrect
generator fixture return types, and dynamic LogRecord attribute access.
@Krishnachaitanyakc Krishnachaitanyakc requested a review from a team as a code owner March 25, 2026 03:55
@Krishnachaitanyakc Krishnachaitanyakc requested review from bogdankostic and removed request for a team March 25, 2026 03:55
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 25, 2026

@Krishnachaitanyakc is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 25, 2026

CLA assistant check
All committers have signed the CLA.

@bogdankostic
Copy link
Copy Markdown
Contributor

Hi @Krishnachaitanyakc, thanks for opening this PR! Could you please sign the CLA?

@bogdankostic bogdankostic added the ignore-for-release-notes PRs with this flag won't be included in the release notes. label Mar 26, 2026
@github-actions github-actions bot added topic:tests topic:build/distribution and removed ignore-for-release-notes PRs with this flag won't be included in the release notes. labels Mar 26, 2026
Copy link
Copy Markdown
Contributor

@bogdankostic bogdankostic left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Krishnachaitanyakc! I left a couple of comments on how we can improve it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As this PR only touches our tests, we don't need a release note. Let's remove this file.

)
assert any(
record.operation_name == "haystack.pipeline.run" for record in records if hasattr(record, "operation_name")
getattr(record, "operation_name", None) == "haystack.pipeline.run"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
getattr(record, "operation_name", None) == "haystack.pipeline.run"
getattr(record, "operation_name") == "haystack.pipeline.run"


assert any(
record.operation_name == "haystack.component.run" for record in records if hasattr(record, "operation_name")
getattr(record, "operation_name", None) == "haystack.component.run"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
getattr(record, "operation_name", None) == "haystack.component.run"
getattr(record, "operation_name") == "haystack.component.run"

)
assert any(
record.operation_name == "haystack.pipeline.run" for record in records if hasattr(record, "operation_name")
getattr(record, "operation_name", None) == "haystack.pipeline.run"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
getattr(record, "operation_name", None) == "haystack.pipeline.run"
getattr(record, "operation_name") == "haystack.pipeline.run"

@@ -57,6 +57,7 @@ def test_current_span(
with tracer.trace("test"):
current_span = tracer.current_span()
assert tracer.current_span() is not None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert tracer.current_span() is not None

Comment on lines +47 to +49
current = tracer.current_span()
assert current is not None
assert isinstance(current.raw_span(), NullSpan)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
current = tracer.current_span()
assert current is not None
assert isinstance(current.raw_span(), NullSpan)
current_span = tracer.current_span()
assert current_span is not None
assert isinstance(current_span.raw_span(), NullSpan)

class TestAutoEnableTracer:
@pytest.fixture()
def configured_opentelemetry_tracing(self) -> None:
def configured_opentelemetry_tracing(self) -> Iterator[None]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's use Generator type here.

Suggested change
def configured_opentelemetry_tracing(self) -> Iterator[None]:
def configured_opentelemetry_tracing(self) -> Generator[None]:

@bogdankostic bogdankostic added the ignore-for-release-notes PRs with this flag won't be included in the release notes. label Mar 26, 2026
The hasattr guard already ensures the attribute exists, so direct
access is safe. Added type: ignore comments since LogRecord doesn't
declare operation_name in its type stubs.
Copy link
Copy Markdown
Contributor

@bogdankostic bogdankostic left a comment

Choose a reason for hiding this comment

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

I made a few comments on how to make the typing checks pass. Also, let's add # type: ignore[func-returns-value] to test_factory.py.

Krishnachaitanyakc and others added 3 commits March 26, 2026 13:26
- Remove unnecessary type: ignore[attr-defined] where hasattr guards exist
- Add type: ignore[func-returns-value] to delete_documents assertion
Copy link
Copy Markdown
Contributor

@bogdankostic bogdankostic left a comment

Choose a reason for hiding this comment

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

Looking good, thanks @Krishnachaitanyakc! :)

@bogdankostic bogdankostic merged commit 948f21b into deepset-ai:main Mar 27, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ignore-for-release-notes PRs with this flag won't be included in the release notes. topic:build/distribution topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants