22import pytest
33from pathlib import Path
44
5- FIXTURES_DIR = Path (__file__ ).parent / 'fixtures'
65BIN_DIR = Path (__file__ ).parent .parent / 'bin'
76
87
8+ def pytest_addoption (parser ):
9+ parser .addoption ('--work-dir' , default = None , help = 'Root temp directory for fixtures and test repos' )
10+
11+
12+ @pytest .fixture (scope = 'session' )
13+ def work_dir (request ):
14+ d = request .config .getoption ('--work-dir' )
15+ if d is None :
16+ pytest .exit (
17+ 'Missing --work-dir. Run the suite via tests/run_tests.sh, '
18+ 'which prepares fixtures and passes --work-dir automatically.' ,
19+ returncode = 1 ,
20+ )
21+ return Path (d )
22+
23+
24+
925def cmd_info (result ):
1026 """Format a CompletedProcess into a readable diagnostic block for assertion messages."""
1127 cmd = ' ' .join (str (a ) for a in result .args )
@@ -31,16 +47,25 @@ def resolve_ref(repo_dir, ref):
3147 return git (repo_dir , 'rev-parse' , ref ).stdout .strip ()
3248
3349
50+ # Multiple tests may use the same fixture name; a counter ensures each gets
51+ # its own subdirectory under work_dir/tests/ without collisions.
52+ _repo_counter = 0
53+
54+
3455@pytest .fixture
35- def make_repo (tmp_path ):
56+ def make_repo (work_dir ):
3657 """Return a factory that creates a git repo from a .fi fixture file."""
58+ global _repo_counter
59+ _repo_counter += 1
60+ idx = _repo_counter
61+
3762 def _make (fixture_name ):
38- repo_dir = tmp_path / fixture_name
39- repo_dir .mkdir ()
63+ repo_dir = work_dir / 'tests' / f' { idx } _ { fixture_name } '
64+ repo_dir .mkdir (parents = True )
4065 git (repo_dir , 'init' )
4166 git (repo_dir , 'config' , 'user.email' , 'test@test' )
4267 git (repo_dir , 'config' , 'user.name' , 'Test' )
43- fi_path = FIXTURES_DIR / f'{ fixture_name } .fi'
68+ fi_path = work_dir / 'fixtures' / f'{ fixture_name } .fi'
4469 with fi_path .open ('rb' ) as f :
4570 subprocess .run (
4671 ['git' , 'fast-import' , '--quiet' ],
0 commit comments