@@ -58,16 +58,13 @@ def _create_test_module(**namespace: Any) -> None:
58
58
59
59
60
60
@pytest .fixture
61
- def create_last_conversation_file ():
61
+ def emtpy_last_conversation_path ():
62
62
path = PYDANTIC_AI_HOME / LAST_CONVERSATION_FILENAME
63
63
64
- def _factory (empty : bool = True ) -> Path :
65
- if empty and path .exists ():
66
- path .unlink ()
64
+ if path .exists ():
65
+ path .unlink ()
67
66
68
- return path
69
-
70
- return _factory
67
+ return path
71
68
72
69
73
70
def test_agent_flag (
@@ -181,36 +178,32 @@ def test_cli_continue_last_conversation(
181
178
args : list [str ],
182
179
capfd : CaptureFixture [str ],
183
180
env : TestEnv ,
184
- create_last_conversation_file : Callable [..., Path ] ,
181
+ emtpy_last_conversation_path : Path ,
185
182
):
186
- last_conversation_path = create_last_conversation_file ()
187
-
188
183
env .set ('OPENAI_API_KEY' , 'test' )
189
184
with cli_agent .override (model = TestModel (custom_output_text = '# world' )):
190
185
assert cli (args ) == 0
191
186
assert capfd .readouterr ().out .splitlines () == snapshot ([IsStr (), '# world' ])
192
- assert last_conversation_path .exists ()
193
- content = last_conversation_path .read_text ()
187
+ assert emtpy_last_conversation_path .exists ()
188
+ content = emtpy_last_conversation_path .read_text ()
194
189
assert content
195
190
196
191
assert cli (args ) == 0
197
192
assert capfd .readouterr ().out .splitlines () == snapshot ([IsStr (), '# world' ])
198
- assert last_conversation_path .exists ()
193
+ assert emtpy_last_conversation_path .exists ()
199
194
# verity that new content is appended to the file
200
- assert len (last_conversation_path .read_text ()) > len (content )
195
+ assert len (emtpy_last_conversation_path .read_text ()) > len (content )
201
196
202
197
203
198
@pytest .mark .parametrize ('args' , [['hello' , '-c' ], ['hello' , '--continue' ]])
204
199
def test_cli_continue_last_conversation_corrupted_file (
205
200
args : list [str ],
206
201
capfd : CaptureFixture [str ],
207
202
env : TestEnv ,
208
- create_last_conversation_file : Callable [..., Path ] ,
203
+ emtpy_last_conversation_path : Path ,
209
204
):
210
- last_conversation_path = create_last_conversation_file ()
211
-
212
205
env .set ('OPENAI_API_KEY' , 'test' )
213
- last_conversation_path .write_text ('not a valid json' )
206
+ emtpy_last_conversation_path .write_text ('not a valid json' )
214
207
with cli_agent .override (model = TestModel (custom_output_text = '# world' )):
215
208
assert cli (args ) == 0
216
209
assert capfd .readouterr ().out .splitlines () == snapshot (
@@ -221,8 +214,8 @@ def test_cli_continue_last_conversation_corrupted_file(
221
214
'# world' ,
222
215
]
223
216
)
224
- assert last_conversation_path .exists ()
225
- assert last_conversation_path .read_text ()
217
+ assert emtpy_last_conversation_path .exists ()
218
+ assert emtpy_last_conversation_path .read_text ()
226
219
227
220
228
221
def test_chat (capfd : CaptureFixture [str ], mocker : MockerFixture , env : TestEnv ):
0 commit comments