Skip to content

fix: non-greedy suite_name regex and remove re.DOTALL in _CASE_REGEX#1309

Open
Shraman123 wants to merge 1 commit into
morganstanley:mainfrom
Shraman123:fix/pytest-case-regex-dotall
Open

fix: non-greedy suite_name regex and remove re.DOTALL in _CASE_REGEX#1309
Shraman123 wants to merge 1 commit into
morganstanley:mainfrom
Shraman123:fix/pytest-case-regex-dotall

Conversation

@Shraman123

@Shraman123 Shraman123 commented May 2, 2026

Copy link
Copy Markdown

Problem

The _CASE_REGEX incorrectly parses nested pytest node IDs.

  1. The suite_name group uses a greedy .+, which consumes the last :: instead of the first.
    Example:

    • Input: OuterClass::InnerClass::test_fn
    • Current: suite_name = "OuterClass::InnerClass"
    • Expected: suite_name = "OuterClass"
  2. The re.DOTALL flag is unnecessary for pytest node IDs (which are single-line)
    and can cause incorrect matches when parametrized values contain newlines.

Fix

  • Make suite_name non-greedy (.+?)
  • Remove re.DOTALL

Impact

  • Correct parsing of nested test identifiers
  • Prevents incorrect serialization of parametrized test cases
  • No behavioral change for standard single-level test IDs

Risk

Low — change is limited to regex parsing logic

Example

Before:
OuterClass::InnerClass::test_fn → suite_name = OuterClass::InnerClass ❌

After:
OuterClass::InnerClass::test_fn → suite_name = OuterClass ✅

The greedy .+ in suite_name consumed all :: separators instead of
stopping at the first one, causing nested test IDs to be mis-parsed.
re.DOTALL was also unnecessary for single-line node IDs and risky
when parametrize values contain embedded newlines.
@Shraman123 Shraman123 requested a review from a team as a code owner May 2, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant