Skip to content

Fix selftests with Pygments >= 2.19.0 #13113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/13112.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed selftest failures in ``test_terminal.py`` with Pygments >= 2.19.0
7 changes: 7 additions & 0 deletions testing/conftest.py
Original file line number Diff line number Diff line change
@@ -3,9 +3,12 @@

from collections.abc import Generator
import dataclasses
import importlib.metadata
import re
import sys

from packaging.version import Version

from _pytest.monkeypatch import MonkeyPatch
from _pytest.pytester import Pytester
import pytest
@@ -168,6 +171,9 @@

Used by tests which check the actual colors output by pytest.
"""
# https://github.com/pygments/pygments/commit/d24e272894a56a98b1b718d9ac5fabc20124882a
pygments_version = Version(importlib.metadata.version("pygments"))
pygments_has_kwspace_hl = pygments_version >= Version("2.19")

Check warning on line 176 in testing/conftest.py

Codecov / codecov/patch

testing/conftest.py#L175-L176

Added lines #L175 - L176 were not covered by tests

class ColorMapping:
COLORS = {
@@ -180,6 +186,7 @@
"bold": "\x1b[1m",
"reset": "\x1b[0m",
"kw": "\x1b[94m",
"kwspace": "\x1b[90m \x1b[39;49;00m" if pygments_has_kwspace_hl else " ",
"hl-reset": "\x1b[39;49;00m",
"function": "\x1b[92m",
"number": "\x1b[94m",
10 changes: 5 additions & 5 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
@@ -1294,13 +1294,13 @@ def test_this():
"=*= FAILURES =*=",
"{red}{bold}_*_ test_this _*_{reset}",
"",
" {reset}{kw}def{hl-reset} {function}test_this{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_this{hl-reset}():{endline}",
"> fail(){endline}",
"",
"{bold}{red}test_color_yes.py{reset}:5: ",
"_ _ * _ _*",
"",
" {reset}{kw}def{hl-reset} {function}fail{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}fail{hl-reset}():{endline}",
"> {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
"{bold}{red}E assert 0{reset}",
"",
@@ -2580,7 +2580,7 @@ def test_foo():
result.stdout.fnmatch_lines(
color_mapping.format_for_fnmatch(
[
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_foo{hl-reset}():{endline}",
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
"{bold}{red}E assert 1 == 10{reset}",
]
@@ -2602,7 +2602,7 @@ def test_foo():
result.stdout.fnmatch_lines(
color_mapping.format_for_fnmatch(
[
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_foo{hl-reset}():{endline}",
" {print}print{hl-reset}({str}'''{hl-reset}{str}{hl-reset}",
"> {str} {hl-reset}{str}'''{hl-reset}); {kw}assert{hl-reset} {number}0{hl-reset}{endline}",
"{bold}{red}E assert 0{reset}",
@@ -2625,7 +2625,7 @@ def test_foo():
result.stdout.fnmatch_lines(
color_mapping.format_for_fnmatch(
[
" {reset}{kw}def{hl-reset} {function}test_foo{hl-reset}():{endline}",
" {reset}{kw}def{hl-reset}{kwspace}{function}test_foo{hl-reset}():{endline}",
"> {kw}assert{hl-reset} {number}1{hl-reset} == {number}10{hl-reset}{endline}",
"{bold}{red}E assert 1 == 10{reset}",
]