syrusakbary / snapshottest

Snapshot Testing utils for Python 📸
MIT License
525 stars 102 forks source link

Parameterized tests with quotes in the parameter produce snapshots with a syntax error #127

Closed lucemia closed 2 years ago

lucemia commented 3 years ago

How to reproduce:

snapshottest==0.5.1

@pytest.mark.parametrize("text", ["'"])
def test_foo(text, snapshot):
   snapshot.assert_match(True) 

generated snapshot test

# -*- coding: utf-8 -*-
# snapshottest: v1 - https://goo.gl/zC4yUc
from __future__ import unicode_literals

from snapshottest import Snapshot

snapshots = Snapshot()

snapshots['test_foo['] 1'] = True

It will raise Syntax error

    snapshots['test_foo['] 1'] = True
                           ^
SyntaxError: invalid syntax
paulmelnikow commented 3 years ago

Thanks for the report! Would welcome a PR that will correctly encode test names for parameterized tests with quotes.

paulmelnikow commented 3 years ago

120 is a similar / the same issue.