Fix selftests with Pygments >= 2.19.0#13113
Conversation
testing/conftest.py
Outdated
| Used by tests which check the actual colors output by pytest. | ||
| """ | ||
| # https://github.com/pygments/pygments/commit/d24e272894a56a98b1b718d9ac5fabc20124882a | ||
| pygments_version = tuple(int(part) for part in pygments.__version__.split(".")[:2]) |
There was a problem hiding this comment.
This is a bit crude, I thought about using packaging.Version instead (pytest already depends on it). Since we only need major/minor, I suppose this is simpler? Happy to adjust if preferred.
Alternatively we could just adjust this without a version check and assume the newest Pygments version?
There was a problem hiding this comment.
Up to you, given these are self tests I'm OK with this solution... if it ever breaks we can just adjust it to something more elaborate with packaging.Version. 👍
testing/conftest.py
Outdated
| import re | ||
| import sys | ||
|
|
||
| import pygments |
There was a problem hiding this comment.
This makes the testsuite explicitly depend on pygments - but the tests in test_terminal.py already fail if pygments is not installed, and it's in optional-dependencies.dev in pyproject.toml, so I suppose that's alright?
There was a problem hiding this comment.
Seems fine to me.
The alternative would be to import-or-skip inside the fixture function.
testing/conftest.py
Outdated
| Used by tests which check the actual colors output by pytest. | ||
| """ | ||
| # https://github.com/pygments/pygments/commit/d24e272894a56a98b1b718d9ac5fabc20124882a | ||
| pygments_version = tuple(int(part) for part in pygments.__version__.split(".")[:2]) |
There was a problem hiding this comment.
Let's fetch the version from Importlib.metadata.version
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks @The-Compiler for tackling this!
testing/conftest.py
Outdated
| Used by tests which check the actual colors output by pytest. | ||
| """ | ||
| # https://github.com/pygments/pygments/commit/d24e272894a56a98b1b718d9ac5fabc20124882a | ||
| pygments_version = tuple(int(part) for part in pygments.__version__.split(".")[:2]) |
There was a problem hiding this comment.
Up to you, given these are self tests I'm OK with this solution... if it ever breaks we can just adjust it to something more elaborate with packaging.Version. 👍
With Pygments 2.19, the Python lexer now emits Text.Whitespace (rather than Text) tokens after "def", which get highlighted as "bright black". See pygments/pygments#1905 Fixes pytest-dev#13112
7972182 to
888cf3f
Compare
|
Updated to use |
for more information, see https://pre-commit.ci
|
Awesome, thanks! |
Backport to 8.3.x: 💚 backport PR created✅ Backport PR branch: Backported as #13116 🤖 @patchback |
Fix selftests with Pygments >= 2.19.0 (cherry picked from commit bdfc3a9)
…dfc3a99bd733f385f150446caef6d5843bb6418/pr-13113 [PR #13113/bdfc3a99 backport][8.3.x] Fix selftests with Pygments >= 2.19.0
With Pygments 2.19, the Python lexer now emits
Text.Whitespace (rather than Text) tokens after "def", which get highlighted as "bright black".
See pygments/pygments#1905
Fixes #13112
(also fixes the current CI failures, I hope!)