Skip to content

Test ID mismatch for parametrized tests with escaped unicode strings #124

@hughhan1

Description

@hughhan1

Problem

When collecting tests that have parametrized values containing escaped unicode (like "\\u2603"), rtest generates different test IDs than pytest, causing pytest to fail with "not found" errors when using --runner pytest.

Reproduction

Given this test:

@pytest.mark.parametrize(
    "test_value,expected", [(True, '"\\u2603"'), (False, '"\u2603"')]
)
def test_json_as_unicode(test_value, expected, app, app_ctx):
    app.json.ensure_ascii = test_value
    rv = app.json.dumps("\N{SNOWMAN}")
    assert rv == expected

pytest generates test IDs:

  • test_json_as_unicode[True-"\\u2603"]
  • test_json_as_unicode[False-"\u2603"]

But rtest generates different IDs (likely without the proper escaping), causing:

ERROR: not found: tests/test_json.py::test_json_as_unicode
(no match in any of [<Module test_json.py>])

This happens on real-world projects like Flask's tests/test_json.py.

Context

The issue seems to be in how we serialize string literals containing backslash escapes when generating test IDs. The source string '"\\u2603"' contains a literal backslash followed by u2603, which pytest preserves verbatim in the test ID, but rtest may be handling the escaping differently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions