diff --git a/tests/test_builders/test_build_html_image.py b/tests/test_builders/test_build_html_image.py
index 6472a97504d..5a061ed4dec 100644
--- a/tests/test_builders/test_build_html_image.py
+++ b/tests/test_builders/test_build_html_image.py
@@ -61,21 +61,36 @@ 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,
- )
+ if docutils.__version_info__[:2] >= (0, 22):
+ assert re.search(
+ '\n'
+ ''
+ '\n',
+ context,
+ )
+ else:
+ # 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
- assert re.search(
- '\n',
- context,
- )
+ if docutils.__version_info__[:2] >= (0, 22):
+ assert re.search(
+ '\n',
+ context,
+ )
+ else:
+ assert re.search(
+ '\n',
+ context,
+ )
@pytest.mark.usefixtures('_http_teapot')