@@ -58,13 +58,16 @@ def _create_test_module(**namespace: Any) -> None:
5858
5959
6060@pytest .fixture
61- def emtpy_last_conversation_path ():
61+ def create_last_conversation_file ():
6262 path = PYDANTIC_AI_HOME / LAST_CONVERSATION_FILENAME
6363
64- if path .exists ():
65- path .unlink ()
64+ def _factory (empty : bool = True ) -> Path :
65+ if empty and path .exists ():
66+ path .unlink ()
6667
67- return path
68+ return path
69+
70+ return _factory
6871
6972
7073def test_agent_flag (
@@ -179,32 +182,36 @@ def test_cli_continue_last_conversation(
179182 args : list [str ],
180183 capfd : CaptureFixture [str ],
181184 env : TestEnv ,
182- emtpy_last_conversation_path : Path ,
185+ create_last_conversation_file : Callable [..., Path ] ,
183186):
187+ last_conversation_path = create_last_conversation_file ()
188+
184189 env .set ('OPENAI_API_KEY' , 'test' )
185190 with cli_agent .override (model = TestModel (custom_output_text = '# world' )):
186191 assert cli (args ) == 0
187192 assert capfd .readouterr ().out .splitlines () == snapshot ([IsStr (), '# world' ])
188- assert emtpy_last_conversation_path .exists ()
189- content = emtpy_last_conversation_path .read_text ()
193+ assert last_conversation_path .exists ()
194+ content = last_conversation_path .read_text ()
190195 assert content
191196
192197 assert cli (args ) == 0
193198 assert capfd .readouterr ().out .splitlines () == snapshot ([IsStr (), '# world' ])
194- assert emtpy_last_conversation_path .exists ()
199+ assert last_conversation_path .exists ()
195200 # verity that new content is appended to the file
196- assert len (emtpy_last_conversation_path .read_text ()) > len (content )
201+ assert len (last_conversation_path .read_text ()) > len (content )
197202
198203
199204@pytest .mark .parametrize ('args' , [['hello' , '-c' ], ['hello' , '--continue' ]])
200205def test_cli_continue_last_conversation_corrupted_file (
201206 args : list [str ],
202207 capfd : CaptureFixture [str ],
203208 env : TestEnv ,
204- emtpy_last_conversation_path : Path ,
209+ create_last_conversation_file : Callable [..., Path ] ,
205210):
211+ last_conversation_path = create_last_conversation_file ()
212+
206213 env .set ('OPENAI_API_KEY' , 'test' )
207- emtpy_last_conversation_path .write_text ('not a valid json' )
214+ last_conversation_path .write_text ('not a valid json' )
208215 with cli_agent .override (model = TestModel (custom_output_text = '# world' )):
209216 assert cli (args ) == 0
210217 assert capfd .readouterr ().out .splitlines () == snapshot (
@@ -215,8 +222,8 @@ def test_cli_continue_last_conversation_corrupted_file(
215222 '# world' ,
216223 ]
217224 )
218- assert emtpy_last_conversation_path .exists ()
219- assert emtpy_last_conversation_path .read_text ()
225+ assert last_conversation_path .exists ()
226+ assert last_conversation_path .read_text ()
220227
221228
222229def test_chat (capfd : CaptureFixture [str ], mocker : MockerFixture , env : TestEnv ):
0 commit comments