pygments / pygments/pygments

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

Open
#2,995 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
885
PR merge metrics
No merged PRs in 30d

Description

Summary

When using the pytest lexer in Pygments, certain forms of pytest output, especially subtest failure block, are not tokenized or highlighted correctly. This leads to inaccurate styling when rendered in downstream tools such as pytest documentation, the pytest website, and other Sphinx-generated docs.

What's Happening

In particular, the lexer does not correctly detect or tokenize:

  • FAILED Subtest: blocks
  • Indentation/continuation lines within subtest output
  • Stack traces inside subtest reports
  • Error-summary formatting that appears after subtests

As a result, rendering shows either:

  • Missing color highlighting
  • Entire blocks treated as plain text
Expected Behaviour

The pytest lexer should correctly highlight subtest output in the same way it highlights standard pytest failure reports, for example:

  • Headers (FAILED, E, etc.) should use the same error tokens
  • Subtest detail lines should inherit traceback/summary highlighting
  • Continuation blocks should follow pytest’s existing multiline output rules

This would ensure that:

  • Documentation examples remain consistently highlighted
  • Pytest output is parsed as expected across tools

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named in the issue. Start by locating the pytest lexer and its existing multiline failure-report rules, then inspect how subtest headers, continuation lines, stack traces, and summaries are tokenized. Done means these subtest forms receive the same appropriate highlighting as standard pytest failure output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.