Skip to content

Commit

Permalink
fix: incorrect marking of TestClass.test_method as unused, close #717
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Negin-Ulster committed Jun 19, 2023
1 parent eb3183d commit f71d1aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/syrupy/extensions/single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ def _read_snapshot_collection(
) -> "SnapshotCollection":
file_ext_len = len(self._file_extension) + 1 if self._file_extension else 0
filename_wo_ext = snapshot_location[:-file_ext_len]
basename = Path(filename_wo_ext).parts[-1]

snapshot_collection = SnapshotCollection(location=snapshot_location)
snapshot_collection.add(Snapshot(name=Path(filename_wo_ext).stem))
snapshot_collection.add(Snapshot(name=basename))
return snapshot_collection

def _read_snapshot_data_from_location(
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/test_single_file_multiple_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,39 @@ def test_dot_in_filename(snapshot):
result.stdout.re_match_lines((r"1 snapshot passed\."))
assert "snapshots unused" not in result.stdout.str()
assert result.ret == 0


def test_class_style(testdir):
"""
Regression test for https://github.com/tophat/syrupy/issues/717
"""

testcase = """
import pytest
from syrupy.extensions.json import JSONSnapshotExtension
@pytest.fixture
def snapshot(snapshot):
return snapshot.use_extension(JSONSnapshotExtension)
class TestFoo:
def test_foo(self, snapshot):
assert { 'key': 'value' } == snapshot
"""

test_file: Path = testdir.makepyfile(test_file=testcase)

result = testdir.runpytest("-v", "--snapshot-update")
result.stdout.re_match_lines((r"1 snapshot generated\."))
assert "deleted" not in result.stdout.str()
assert result.ret == 0

snapshot_file = (
Path(test_file).parent / "__snapshots__" / "test_file" / "TestFoo.test_foo.json"
)
assert snapshot_file.exists()

result = testdir.runpytest("-v")
result.stdout.re_match_lines((r"1 snapshot passed\."))
assert "snapshots unused" not in result.stdout.str()
assert result.ret == 0

1 comment on commit f71d1aa

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: f71d1aa Previous: 783fc5c Ratio
benchmarks/test_1000x.py::test_1000x_reads 0.579345497818308 iter/sec (stddev: 0.07971788674602952) 0.6308297334975749 iter/sec (stddev: 0.051713625654997736) 1.09
benchmarks/test_1000x.py::test_1000x_writes 0.5748387652193828 iter/sec (stddev: 0.05900668003193158) 0.6342425353394988 iter/sec (stddev: 0.0828116786033814) 1.10
benchmarks/test_standard.py::test_standard 0.5521781179110627 iter/sec (stddev: 0.11408890946762458) 0.6101786430715832 iter/sec (stddev: 0.0866700410881286) 1.11

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.