Skip to content

Add PytestSessionLexer to properly highlight pytest session output#2996

Open
emilymamcarz wants to merge 1 commit intopygments:masterfrom
emilymamcarz:fix-pytest-subtest-highlighting
Open

Add PytestSessionLexer to properly highlight pytest session output#2996
emilymamcarz wants to merge 1 commit intopygments:masterfrom
emilymamcarz:fix-pytest-subtest-highlighting

Conversation

@emilymamcarz
Copy link

Summary

This PR adds a dedicated PytestSessionLexer to Pygments to properly highlight pytest session output in documentation, examples, and testing outputs. Previously, the subtest lines in documentation were incorrectly highlighted, implying all subtests passed. This lexer fixes that while preserving existing highlighting for section headers, captured output, assertions, and tracebacks.

Details

PytestSessionLexer is a RegexLexer with:

  • Section header highlighting (==== FAILURES ====)
  • Subtest line highlighting (e.g., FAILED [100%] tests/test_file.py::TestClass::test_method[subtest x])
  • Captured stdout/stderr blocks
  • Assertion errors (E AssertionError)
  • File:line references (tests/test_file.py:14: AssertionError)
  • Fallback to Text for other lines
    The lexer is registered under the alias "pytest".

This PR resolves #2995

@birkenfeld birkenfeld added the new lexer PRs with wholly new lexers label Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new lexer PRs with wholly new lexers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Pytest Subtest Output Not Highlighted Correctly by Pygments Pytest Lexer

2 participants