File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -82,9 +82,10 @@ def _read_snapshot_collection(
8282 ) -> "SnapshotCollection" :
8383 file_ext_len = len (self ._file_extension ) + 1 if self ._file_extension else 0
8484 filename_wo_ext = snapshot_location [:- file_ext_len ]
85+ basename = Path (filename_wo_ext ).parts [- 1 ]
8586
8687 snapshot_collection = SnapshotCollection (location = snapshot_location )
87- snapshot_collection .add (Snapshot (name = Path ( filename_wo_ext ). stem ))
88+ snapshot_collection .add (Snapshot (name = basename ))
8889 return snapshot_collection
8990
9091 def _read_snapshot_data_from_location (
Original file line number Diff line number Diff line change @@ -38,3 +38,39 @@ def test_dot_in_filename(snapshot):
3838 result .stdout .re_match_lines ((r"1 snapshot passed\." ))
3939 assert "snapshots unused" not in result .stdout .str ()
4040 assert result .ret == 0
41+
42+
43+ def test_class_style (testdir ):
44+ """
45+ Regression test for https://github.com/tophat/syrupy/issues/717
46+ """
47+
48+ testcase = """
49+ import pytest
50+ from syrupy.extensions.json import JSONSnapshotExtension
51+
52+ @pytest.fixture
53+ def snapshot(snapshot):
54+ return snapshot.use_extension(JSONSnapshotExtension)
55+
56+ class TestFoo:
57+ def test_foo(self, snapshot):
58+ assert { 'key': 'value' } == snapshot
59+ """
60+
61+ test_file : Path = testdir .makepyfile (test_file = testcase )
62+
63+ result = testdir .runpytest ("-v" , "--snapshot-update" )
64+ result .stdout .re_match_lines ((r"1 snapshot generated\." ))
65+ assert "deleted" not in result .stdout .str ()
66+ assert result .ret == 0
67+
68+ snapshot_file = (
69+ Path (test_file ).parent / "__snapshots__" / "test_file" / "TestFoo.test_foo.json"
70+ )
71+ assert snapshot_file .exists ()
72+
73+ result = testdir .runpytest ("-v" )
74+ result .stdout .re_match_lines ((r"1 snapshot passed\." ))
75+ assert "snapshots unused" not in result .stdout .str ()
76+ assert result .ret == 0
You can’t perform that action at this time.
0 commit comments