diff --git a/src/syrupy/serializers/raw_single.py b/src/syrupy/serializers/raw_single.py index e4ef8c15..6c040a67 100644 --- a/src/syrupy/serializers/raw_single.py +++ b/src/syrupy/serializers/raw_single.py @@ -34,7 +34,12 @@ def discover_snapshots(self, filepath: str) -> "SnapshotFile": return snapshot_file def get_file_basename(self, index: int) -> str: - return self.__clean_filename(self.get_snapshot_name(index=index)) + return self.get_snapshot_name(index=index) + + def get_snapshot_name(self, index: int = 0) -> str: + return self.__clean_filename( + super(RawSingleSnapshotSerializer, self).get_snapshot_name(index=index) + ) @property def snapshot_subdirectory_name(self) -> str: diff --git a/tests/__snapshots__/test_amber_serializer.ambr b/tests/__snapshots__/test_amber_serializer.ambr index ccb6700d..e1545f21 100644 --- a/tests/__snapshots__/test_amber_serializer.ambr +++ b/tests/__snapshots__/test_amber_serializer.ambr @@ -1,6 +1,15 @@ -# name: TestClass.test_name +# name: TestClass.test_class_method_name 'this is in a test class' --- +# name: TestClass.test_class_method_parametrized[a] + 'a' +--- +# name: TestClass.test_class_method_parametrized[b] + 'b' +--- +# name: TestClass.test_class_method_parametrized[c] + 'c' +--- # name: test_bool[False] False --- diff --git a/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_name.raw b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_name.raw new file mode 100644 index 00000000..20661334 --- /dev/null +++ b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_name.raw @@ -0,0 +1 @@ +this is in a test class \ No newline at end of file diff --git a/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedx.raw b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedx.raw new file mode 100644 index 00000000..c1b0730e --- /dev/null +++ b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedx.raw @@ -0,0 +1 @@ +x \ No newline at end of file diff --git a/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedy.raw b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedy.raw new file mode 100644 index 00000000..e25f1814 --- /dev/null +++ b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedy.raw @@ -0,0 +1 @@ +y \ No newline at end of file diff --git a/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedz.raw b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedz.raw new file mode 100644 index 00000000..fa7af8bf --- /dev/null +++ b/tests/__snapshots__/test_raw_single_serializer/TestClass.test_class_method_parametrizedz.raw @@ -0,0 +1 @@ +z \ No newline at end of file diff --git a/tests/test_amber_serializer.py b/tests/test_amber_serializer.py index bb24cfa9..c7513fcc 100644 --- a/tests/test_amber_serializer.py +++ b/tests/test_amber_serializer.py @@ -96,5 +96,9 @@ def test_cycle(cyclic, snapshot): class TestClass: - def test_name(self, snapshot): + def test_class_method_name(self, snapshot): assert snapshot == "this is in a test class" + + @pytest.mark.parametrize("actual", ["a", "b", "c"]) + def test_class_method_parametrized(self, snapshot, actual): + assert snapshot == actual diff --git a/tests/test_raw_single_serializer.py b/tests/test_raw_single_serializer.py index c29fed8f..20141451 100644 --- a/tests/test_raw_single_serializer.py +++ b/tests/test_raw_single_serializer.py @@ -27,3 +27,12 @@ def test_does_not_write_non_binary(testdir, snapshot_raw: "SnapshotAssertion"): with pytest.raises(TypeError, match="Expected 'bytes', got 'str'"): snapshot_raw.serializer._write_snapshot_to_file(snapshot_file) assert not os.path.exists(snapshot_file.filepath) + + +class TestClass: + def test_class_method_name(self, snapshot_raw): + assert snapshot_raw == b"this is in a test class" + + @pytest.mark.parametrize("content", [b"x", b"y", b"z"]) + def test_class_method_parametrized(self, snapshot_raw, content): + assert snapshot_raw == content