Skip to content

Commit 87684e4

Browse files
committed
Fix mocking of md.preprocessors in tests
The `md.preprocessors` attribute wasn't being mocked correctly and returned a new mock object instead of the custom mock object we wanted. The tests passed anyway, because the only thing that was used was the `highlight` return value, which evaluates to `True` when it is a new mock object instead of a proper `bool` value, but now that the type of the preprocessor is checked to be able to call `highlight`, the tests failed. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 7cddc88 commit 87684e4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tests/test_do_format.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from unittest import mock
99

1010
import pytest
11+
from pymdownx.superfences import SuperFencesBlockPreprocessor
1112

1213
from frequenz.pymdownx.superfences.filter_lines import (
1314
LinesRange,
@@ -21,9 +22,10 @@
2122
def md_mock() -> Iterator[mock.MagicMock]:
2223
"""Mock the `md` object."""
2324
md = mock.MagicMock()
24-
preprocessor = mock.MagicMock()
25-
preprocessor.highlight.side_effect = True
26-
md.preprocessors.return_value = {"fenced_code_block": preprocessor}
25+
preprocessor = mock.MagicMock(spec=SuperFencesBlockPreprocessor)
26+
preprocessor.highlight.return_value = True
27+
preprocessors = {"fenced_code_block": preprocessor}
28+
md.preprocessors.__getitem__.side_effect = preprocessors.__getitem__
2729
yield md
2830

2931

0 commit comments

Comments
 (0)