https://github.com/sphinx-doc/sphinx/commit/5ff3740063c1ac57f17ecd697bcd06cc1de4e75c

--- sphinx-7.4.7/tests/test_builders/test_build_html_code.py.orig
+++ sphinx-7.4.7/tests/test_builders/test_build_html_code.py
@@ -1,3 +1,4 @@
+import pygments
 import pytest
 
 
@@ -24,11 +25,16 @@
 
 @pytest.mark.sphinx('html', testroot='reST-code-role')
 def test_html_code_role(app):
+    if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
+        sp = '<span class="w"> </span>'
+    else:
+        sp = ' '
+
     app.build()
     content = (app.outdir / 'index.html').read_text(encoding='utf8')
 
     common_content = (
-        '<span class="k">def</span> <span class="nf">foo</span>'
+        f'<span class="k">def</span>{sp}<span class="nf">foo</span>'
         '<span class="p">(</span>'
         '<span class="mi">1</span> '
         '<span class="o">+</span> '
--- sphinx-7.4.7/tests/test_builders/test_build_latex.py.orig
+++ sphinx-7.4.7/tests/test_builders/test_build_latex.py
@@ -8,6 +8,7 @@
 from shutil import copyfile
 from subprocess import CalledProcessError
 
+import pygments
 import pytest
 
 from sphinx.builders.latex import default_latex_documents
@@ -1677,12 +1678,16 @@
 
 @pytest.mark.sphinx('latex', testroot='reST-code-role')
 def test_latex_code_role(app):
+    if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
+        sp = r'\PYG{+w}{ }'
+    else:
+        sp = ' '
+
     app.build()
     content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
 
     common_content = (
-        r'\PYG{k}{def} '
-        r'\PYG{n+nf}{foo}'
+        r'\PYG{k}{def}' + sp + r'\PYG{n+nf}{foo}'
         r'\PYG{p}{(}'
         r'\PYG{l+m+mi}{1} '
         r'\PYG{o}{+} '
--- sphinx-7.4.7/tests/test_directives/test_directive_code.py.orig
+++ sphinx-7.4.7/tests/test_directives/test_directive_code.py
@@ -2,6 +2,7 @@
 
 import os.path
 
+import pygments
 import pytest
 from docutils import nodes
 
@@ -405,6 +406,11 @@
 
 @pytest.mark.sphinx('html', testroot='directive-code')
 def test_literal_include_linenos(app, status, warning):
+    if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
+        sp = '<span class="w"> </span>'
+    else:
+        sp = ' '
+
     app.build(filenames=[app.srcdir / 'linenos.rst'])
     html = (app.outdir / 'linenos.html').read_text(encoding='utf8')
 
@@ -417,7 +423,7 @@
             '# Literally included file using Python highlighting</span>' in html)
 
     # :lines: 5-9
-    assert ('<span class="linenos">5</span><span class="k">class</span> '
+    assert (f'<span class="linenos">5</span><span class="k">class</span>{sp}'
             '<span class="nc">Foo</span><span class="p">:</span>' in html)
 
 
@@ -549,11 +555,16 @@
 
 @pytest.mark.sphinx('html', testroot='directive-code')
 def test_linenothreshold(app, status, warning):
+    if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
+        sp = '<span class="w"> </span>'
+    else:
+        sp = ' '
+
     app.build(filenames=[app.srcdir / 'linenothreshold.rst'])
     html = (app.outdir / 'linenothreshold.html').read_text(encoding='utf8')
 
     # code-block using linenothreshold
-    assert ('<span class="linenos">1</span><span class="k">class</span> '
+    assert (f'<span class="linenos">1</span><span class="k">class</span>{sp}'
             '<span class="nc">Foo</span><span class="p">:</span>' in html)
 
     # code-block not using linenothreshold (no line numbers)
--- sphinx-7.4.7/tests/test_extensions/test_ext_viewcode.py.orig
+++ sphinx-7.4.7/tests/test_extensions/test_ext_viewcode.py
@@ -3,10 +3,16 @@
 import re
 import shutil
 
+import pygments
 import pytest
 
 
 def check_viewcode_output(app, warning):
+    if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
+        sp = '<span> </span>'
+    else:
+        sp = ' '
+
     warnings = re.sub(r'\\+', '/', warning.getvalue())
     assert re.findall(
         r"index.rst:\d+: WARNING: Object named 'func1' not found in include " +
@@ -32,7 +38,7 @@
     assert ('<div class="viewcode-block" id="Class1">\n'
             '<a class="viewcode-back" href="../../index.html#spam.Class1">[docs]</a>\n') in result
     assert '<span>@decorator</span>\n' in result
-    assert '<span>class</span> <span>Class1</span><span>:</span>\n' in result
+    assert f'<span>class</span>{sp}<span>Class1</span><span>:</span>\n' in result
     assert '<span>    </span><span>&quot;&quot;&quot;</span>\n' in result
     assert '<span>    this is Class1</span>\n' in result
     assert '<span>    &quot;&quot;&quot;</span>\n' in result
--- sphinx-7.4.7/tests/test_highlighting.py.orig
+++ sphinx-7.4.7/tests/test_highlighting.py
@@ -9,7 +9,7 @@
 
 from sphinx.highlighting import PygmentsBridge
 
-if tuple(map(int, pygments.__version__.split('.')))[:2] < (2, 18):
+if tuple(map(int, pygments.__version__.split('.')[:2])) < (2, 18):
     from pygments.formatter import Formatter
     Formatter.__class_getitem__ = lambda cls, name: cls
 
--- sphinx-7.4.7/tests/test_intl/test_intl.py.orig
+++ sphinx-7.4.7/tests/test_intl/test_intl.py
@@ -9,6 +9,7 @@
 import shutil
 import time
 
+import pygments
 import pytest
 from babel.messages import mofile, pofile
 from babel.messages.catalog import Catalog
@@ -1337,6 +1338,11 @@
 @pytest.mark.sphinx('html')
 @pytest.mark.test_params(shared_result='test_intl_basic')
 def test_additional_targets_should_not_be_translated(app):
+    if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
+        sp = '<span class="w"> </span>'
+    else:
+        sp = ' '
+
     app.build()
     # [literalblock.txt]
     result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
@@ -1371,7 +1377,7 @@
     # doctest block should not be translated but be highlighted
     expected_expr = (
         """<span class="gp">&gt;&gt;&gt; </span>"""
-        """<span class="kn">import</span> <span class="nn">sys</span>  """
+        f"""<span class="kn">import</span>{sp}<span class="nn">sys</span>  """
         """<span class="c1"># sys importing</span>""")
     assert_count(expected_expr, result, 1)
 
@@ -1413,6 +1419,11 @@
     },
 )
 def test_additional_targets_should_be_translated(app):
+    if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19):
+        sp = '<span class="w"> </span>'
+    else:
+        sp = ' '
+
     app.build()
     # [literalblock.txt]
     result = (app.outdir / 'literalblock.html').read_text(encoding='utf8')
@@ -1456,7 +1467,7 @@
     # doctest block should not be translated but be highlighted
     expected_expr = (
         """<span class="gp">&gt;&gt;&gt; </span>"""
-        """<span class="kn">import</span> <span class="nn">sys</span>  """
+        f"""<span class="kn">import</span>{sp}<span class="nn">sys</span>  """
         """<span class="c1"># SYS IMPORTING</span>""")
     assert_count(expected_expr, result, 1)
 
