diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index a89a6fcaf..5707d38b2 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -8,6 +8,7 @@ from itertools import chain, cycle
from pathlib import Path
from unittest.mock import ANY, call, patch
+import docutils
import pytest
from html5lib import HTMLParser
@@ -1645,8 +1646,11 @@ def test_html_scaled_image_link(app):
assert re.search('\n
', context)
# scaled_image_link
+ # Docutils 0.21 adds a newline before the closing tag
+ closing_space = "\n" if docutils.__version_info__[:2] >= (0, 21) else ""
assert re.search('\n'
- '
',
+ '
'
+ f'{closing_space}',
context)
# no-scaled-link class disables the feature