Skip to content

test: make WordExtractor close test deterministic#35654

Closed
princepal9120 wants to merge 2 commits into
langgenius:mainfrom
princepal9120:anant/dify-fix-b-word-close
Closed

test: make WordExtractor close test deterministic#35654
princepal9120 wants to merge 2 commits into
langgenius:mainfrom
princepal9120:anant/dify-fix-b-word-close

Conversation

@princepal9120
Copy link
Copy Markdown
Contributor

@princepal9120 princepal9120 commented Apr 28, 2026

Summary

  • Makes WordExtractor.close() coverage deterministic.
  • Replaces a runtime-warning based AsyncMock/GC assertion with a direct awaitable close-result stub.
  • Keeps the test focused on the extractor behavior instead of unrelated coroutine cleanup timing.
  • Removes now-unused gc, warnings, and AsyncMock imports.

Why

The previous test could observe coroutine warnings emitted by earlier tests, which made the assertion flaky and unrelated to WordExtractor.close() itself.

Validation

  • python3 -m py_compile api/tests/unit_tests/core/rag/extractor/test_word_extractor.py

Not run: targeted pytest, because dependency setup failed locally with No space left on device while downloading packages.

Fixes #35651
close #35652

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-29 01:59:49.835362992 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-29 01:59:37.600256147 +0000
@@ -4466,21 +4466,21 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `document_model` with type `Document | None` in function `core.rag.extractor.notion_extractor.NotionExtractor.update_last_edited_time` [bad-argument-type]
    --> tests/unit_tests/core/rag/extractor/test_notion_extractor.py:435:43
 ERROR Type `object` is not iterable [not-iterable]
-  --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:92:9
+  --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:90:9
 ERROR `Any | None` is not assignable to attribute `FILES_URL` with type `str` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:211:33
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:209:33
 ERROR `Any | None` is not assignable to attribute `INTERNAL_FILES_URL` with type `str` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:212:42
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:210:42
 ERROR `Literal['Dify']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:233:14
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:231:14
 ERROR `Literal[' HYPERLINK "http://example.com" ']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:286:22
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:284:22
 ERROR `Literal['Example']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:298:15
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:296:15
 ERROR `Literal['Dify']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:688:14
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:689:14
 ERROR `Literal['john@test.com']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:728:14
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:729:14
 ERROR Argument `Literal['semantic_search']` is not assignable to parameter `retrieval_method` with type `RetrievalMethod` in function `core.rag.index_processor.processor.paragraph_index_processor.ParagraphIndexProcessor.retrieve` [bad-argument-type]
    --> tests/unit_tests/core/rag/indexing/processor/test_paragraph_index_processor.py:246:39
 ERROR Argument `Literal['semantic_search']` is not assignable to parameter `retrieval_method` with type `RetrievalMethod` in function `core.rag.index_processor.processor.parent_child_index_processor.ParentChildIndexProcessor.retrieve` [bad-argument-type]

@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-29 02:09:59.613376192 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-29 02:09:46.417242726 +0000
@@ -4466,17 +4466,17 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `document_model` with type `Document | None` in function `core.rag.extractor.notion_extractor.NotionExtractor.update_last_edited_time` [bad-argument-type]
    --> tests/unit_tests/core/rag/extractor/test_notion_extractor.py:435:43
 ERROR Type `object` is not iterable [not-iterable]
-  --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:92:9
+  --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:90:9
 ERROR `Any | None` is not assignable to attribute `FILES_URL` with type `str` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:211:33
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:209:33
 ERROR `Any | None` is not assignable to attribute `INTERNAL_FILES_URL` with type `str` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:212:42
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:210:42
 ERROR `Literal['Dify']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:233:14
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:231:14
 ERROR `Literal[' HYPERLINK "http://example.com" ']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:286:22
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:284:22
 ERROR `Literal['Example']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:298:15
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:296:15
 ERROR `Literal['Dify']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]
    --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:688:14
 ERROR `Literal['john@test.com']` is not assignable to attribute `text` with type `Ellipsis` [bad-assignment]

@crazywoola
Copy link
Copy Markdown
Member

Thanks for the contribution, @princepal9120 — really appreciate the thorough write-up and the clean refactor here.

Closing this in favor of #35652, which was opened a few hours earlier and targets the same flake (#35651). To keep things fair, we're going FIFO on duplicates, so the older PR got the merge.

Your approach (custom awaitable + MagicMock assertion) is also a perfectly valid way to test this, and the description was great — please don't let this discourage you from sending more PRs our way. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky CI failure in WordExtractor close test

2 participants