Skip to content

refactor(tests): replace logger mocks with caplog in trace provider tests#38569

Merged
asukaminato0721 merged 1 commit into
langgenius:mainfrom
melooooooo:refactor/caplog-trace-provider-tests
Jul 9, 2026
Merged

refactor(tests): replace logger mocks with caplog in trace provider tests#38569
asukaminato0721 merged 1 commit into
langgenius:mainfrom
melooooooo:refactor/caplog-trace-provider-tests

Conversation

@melooooooo

@melooooooo melooooooo commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of #37468.

Replaces the remaining logger_mock = MagicMock() + monkeypatch.setattr(..., "logger", ...) patterns with pytest's caplog fixture in the trace provider tests, following the approach established in earlier PRs for this issue (e.g. #37922, #37890). These two files were found via code search after the files listed in the issue thread were already converted on main:

  • api/providers/trace/trace-aliyun/tests/unit_tests/aliyun_trace/test_aliyun_trace.py: test_get_project_url_error now asserts on caplog.text instead of logger_mock.info.assert_called().
  • api/providers/trace/trace-tencent/tests/unit_tests/tencent_trace/test_client.py: removed the logger MagicMock from the patch_core_components fixture; the five tests that asserted on logger.debug / logger.exception calls now assert on captured log records, checking both level and message so the assertions are strictly stronger than before.

Screenshots

N/A (test-only change)

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

Made with Cursor

From Cursor

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 52.58% 52.58% +0.00%
Strict coverage 52.09% 52.10% +0.00%
Typed symbols 32,521 32,523 +2
Untyped symbols 29,605 29,605 0
Modules 2981 2981 0

@melooooooo melooooooo marked this pull request as ready for review July 9, 2026 06:31
@melooooooo melooooooo requested a review from QuantumGhost as a code owner July 9, 2026 06:31
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. refactor labels Jul 9, 2026
@melooooooo

Copy link
Copy Markdown
Contributor Author

Marking this ready for review — all tests, style, and type checks are green.

Note on the "Validate PR title" check: the initial run failed due to a CI runner timeout (job hung for exactly 10m with no steps executed). A subsequent run of the same check passed: https://github.com/langgenius/dify/actions/runs/28951634957/job/85906573979. The stale failure entry can be ignored.

@asukaminato0721 asukaminato0721 enabled auto-merge July 9, 2026 08:33
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Jul 9, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 9, 2026
Merged via the queue into langgenius:main with commit dc1131b Jul 9, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants