44import tempfile
55import textwrap
66
7+ import _pytest .fixtures
8+ from inline_snapshot ._external ._external_file import ExternalFile
79import pytest
8- from syrupy .assertion import SnapshotAssertion
910
1011from .diff import Diff
1112from .file import MirrorFile
@@ -19,8 +20,14 @@ def test_data_path(global_test_data_path: AbsDir) -> AbsDir:
1920
2021
2122@pytest .fixture
22- def test_name (file : MirrorFile ) -> str :
23- return os .fspath (file .target )
23+ def test_name (file : MirrorFile , request : _pytest .fixtures .FixtureRequest ) -> str :
24+ while not isinstance (request , _pytest .fixtures .TopRequest ):
25+ assert isinstance (request , _pytest .fixtures .SubRequest )
26+ request = request ._parent_request
27+ func_name : str = request .node .function .__name__
28+ assert func_name .startswith ("test_diff_" )
29+ name = func_name .replace ("test_diff_" , "" , count = 1 )
30+ return os .fspath (RelDir (name ) / file .target )
2431
2532
2633@pytest .mark .parametrize (
@@ -35,7 +42,7 @@ def test_name(file: MirrorFile) -> str:
3542 ],
3643)
3744def test_diff_apply_new_file (
38- file : MirrorFile , test_data_path : AbsDir , snapshot : SnapshotAssertion , local_git_repo : GitDir
45+ file : MirrorFile , test_data_path : AbsDir , text_snapshot : ExternalFile , local_git_repo : GitDir
3946) -> None :
4047 remote = AbsDir (tempfile .mkdtemp ())
4148 add_commit (remote , test_data_path / RelDir ("remote" ))
@@ -47,7 +54,7 @@ def test_diff_apply_new_file(
4754 shutil .copy2 (current_path , tmp_filepath )
4855 diff .apply (local_git_repo )
4956 with open (tmp_filepath ) as f :
50- assert f .read () == snapshot
57+ assert f .read () == text_snapshot
5158
5259
5360@pytest .mark .typed
@@ -144,7 +151,7 @@ def test_diff_from_commit_empty(local_git_repo: GitDir) -> None:
144151 ],
145152)
146153def test_diff_apply_versioned_file (
147- file : MirrorFile , test_data_path : AbsDir , snapshot : SnapshotAssertion , local_git_repo : GitDir
154+ file : MirrorFile , test_data_path : AbsDir , text_snapshot : ExternalFile , local_git_repo : GitDir
148155) -> None :
149156 test_data_path /= RelDir ("merge" )
150157 remote_path = GitDir (tempfile .mkdtemp (), check = False )
@@ -164,4 +171,4 @@ def test_diff_apply_versioned_file(
164171 shutil .copy2 (test_data_path / file .target , local_git_repo / file .target )
165172 diff .apply (local_git_repo )
166173 with open (local_git_repo / file .target ) as f :
167- assert f .read () == snapshot
174+ assert f .read () == text_snapshot
0 commit comments