Skip to content

Python tool for converting files and office documents to Markdown.

Exercise real installed OCR plugin discovery in registration tests (#2588)

Adam Fourney64e3d67b3ba9
diff --git a/packages/markitdown-ocr/tests/test_docx_inheritance.py b/packages/markitdown-ocr/tests/test_docx_inheritance.py
index 3cbbf99b..7cf02d70 100644
--- a/packages/markitdown-ocr/tests/test_docx_inheritance.py
+++ b/packages/markitdown-ocr/tests/test_docx_inheritance.py
@@ -15,7 +15,6 @@ from markitdown import FileConversionException, MarkItDown, StreamInfo
from markitdown.converters import DocxConverter
from markitdown.converters import _docx_converter
import markitdown._markitdown as markitdown_module
-from markitdown_ocr import _plugin
from markitdown_ocr._docx_converter_with_ocr import DocxConverterWithOCR
from markitdown_ocr._ocr_service import OCRResult
@@ -82,10 +81,7 @@ def test_docx_ocr_is_a_thin_subclass() -> None:
def test_plugin_registration_full_trip(monkeypatch: pytest.MonkeyPatch) -> None:
- entry_point = Mock()
- entry_point.load.return_value = _plugin
- entry_points = Mock(return_value=[entry_point])
- monkeypatch.setattr(markitdown_module, "entry_points", entry_points)
+ # Reset the cache so discovery reads the installed package entry points.
monkeypatch.setattr(markitdown_module, "_plugins", None)
client = Mock()
client.chat.completions.create.return_value.choices = [
@@ -111,7 +107,6 @@ def test_plugin_registration_full_trip(monkeypatch: pytest.MonkeyPatch) -> None:
"*[Image OCR]\nRecognized\\_text\n[End OCR]*\n\n"
"After\n\n**Native content**"
)
- entry_points.assert_called_once_with(group="markitdown.plugin")
client.chat.completions.create.assert_called_once()
request = client.chat.completions.create.call_args.kwargs
assert request["model"] == "vision-model"
diff --git a/packages/markitdown-ocr/tests/test_pptx_inheritance.py b/packages/markitdown-ocr/tests/test_pptx_inheritance.py
index 6d1dbd6d..6ee3b89d 100644
--- a/packages/markitdown-ocr/tests/test_pptx_inheritance.py
+++ b/packages/markitdown-ocr/tests/test_pptx_inheritance.py
@@ -17,7 +17,6 @@ from markitdown import FileConversionException, MarkItDown, StreamInfo
from markitdown.converters import PptxConverter
from markitdown.converters import _pptx_converter
import markitdown._markitdown as markitdown_module
-from markitdown_ocr import _plugin
from markitdown_ocr._ocr_service import LLMVisionOCRService, OCRResult
from markitdown_ocr._pptx_converter_with_ocr import PptxConverterWithOCR
@@ -245,10 +244,7 @@ def test_svg_metadata_reaches_bundled_vision_request() -> None:
def test_plugin_full_trip_with_mocked_model_only(
monkeypatch: pytest.MonkeyPatch, caption_succeeds: bool
) -> None:
- entry_point = Mock()
- entry_point.load.return_value = _plugin
- entry_points = Mock(return_value=[entry_point])
- monkeypatch.setattr(markitdown_module, "entry_points", entry_points)
+ # Reset the cache so discovery reads the installed package entry points.
monkeypatch.setattr(markitdown_module, "_plugins", None)
client = Mock()
response = Mock(choices=[Mock(message=Mock(content="Recognized_text"))])
@@ -282,7 +278,6 @@ def test_plugin_full_trip_with_mocked_model_only(
+ expected_image
+ "\n\n### Notes:\nSpeaker notes"
)
- entry_points.assert_called_once_with(group="markitdown.plugin")
assert client.chat.completions.create.call_count == (1 if caption_succeeds else 2)
for call in client.chat.completions.create.call_args_list:
request = call.kwargs
diff --git a/packages/markitdown-ocr/tests/test_xlsx_inheritance.py b/packages/markitdown-ocr/tests/test_xlsx_inheritance.py
index 98a104b8..c94c8fac 100644
--- a/packages/markitdown-ocr/tests/test_xlsx_inheritance.py
+++ b/packages/markitdown-ocr/tests/test_xlsx_inheritance.py
@@ -22,7 +22,6 @@ from markitdown import FileConversionException, MarkItDown, StreamInfo
from markitdown.converters import XlsxConverter
from markitdown.converters import _xlsx_converter
import markitdown._markitdown as markitdown_module
-from markitdown_ocr import _plugin
from markitdown_ocr._ocr_service import OCRResult
from markitdown_ocr._xlsx_converter_with_ocr import XlsxConverterWithOCR
@@ -82,11 +81,7 @@ def test_ocr_is_a_thin_subclass_with_native_acceptance_and_signature() -> None:
def test_plugin_full_trip_uses_native_cells_and_original_image(
monkeypatch: pytest.MonkeyPatch,
) -> None:
- entry_point = Mock()
- entry_point.load.return_value = _plugin
- monkeypatch.setattr(
- markitdown_module, "entry_points", Mock(return_value=[entry_point])
- )
+ # Reset the cache so discovery reads the installed package entry points.
monkeypatch.setattr(markitdown_module, "_plugins", None)
client = Mock()
client.chat.completions.create.return_value.choices = [