Skip to content

Commit 909cabd

Browse files
committed
try to fix coverage
1 parent e38df74 commit 909cabd

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

tests/test_cli.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7073
def test_agent_flag(
@@ -178,32 +181,36 @@ def test_cli_continue_last_conversation(
178181
args: list[str],
179182
capfd: CaptureFixture[str],
180183
env: TestEnv,
181-
emtpy_last_conversation_path: Path,
184+
create_last_conversation_file: Callable[..., Path],
182185
):
186+
last_conversation_path = create_last_conversation_file()
187+
183188
env.set('OPENAI_API_KEY', 'test')
184189
with cli_agent.override(model=TestModel(custom_output_text='# world')):
185190
assert cli(args) == 0
186191
assert capfd.readouterr().out.splitlines() == snapshot([IsStr(), '# world'])
187-
assert emtpy_last_conversation_path.exists()
188-
content = emtpy_last_conversation_path.read_text()
192+
assert last_conversation_path.exists()
193+
content = last_conversation_path.read_text()
189194
assert content
190195

191196
assert cli(args) == 0
192197
assert capfd.readouterr().out.splitlines() == snapshot([IsStr(), '# world'])
193-
assert emtpy_last_conversation_path.exists()
198+
assert last_conversation_path.exists()
194199
# verity that new content is appended to the file
195-
assert len(emtpy_last_conversation_path.read_text()) > len(content)
200+
assert len(last_conversation_path.read_text()) > len(content)
196201

197202

198203
@pytest.mark.parametrize('args', [['hello', '-c'], ['hello', '--continue']])
199204
def test_cli_continue_last_conversation_corrupted_file(
200205
args: list[str],
201206
capfd: CaptureFixture[str],
202207
env: TestEnv,
203-
emtpy_last_conversation_path: Path,
208+
create_last_conversation_file: Callable[..., Path],
204209
):
210+
last_conversation_path = create_last_conversation_file()
211+
205212
env.set('OPENAI_API_KEY', 'test')
206-
emtpy_last_conversation_path.write_text('not a valid json')
213+
last_conversation_path.write_text('not a valid json')
207214
with cli_agent.override(model=TestModel(custom_output_text='# world')):
208215
assert cli(args) == 0
209216
assert capfd.readouterr().out.splitlines() == snapshot(
@@ -214,8 +221,8 @@ def test_cli_continue_last_conversation_corrupted_file(
214221
'# world',
215222
]
216223
)
217-
assert emtpy_last_conversation_path.exists()
218-
assert emtpy_last_conversation_path.read_text()
224+
assert last_conversation_path.exists()
225+
assert last_conversation_path.read_text()
219226

220227

221228
def test_chat(capfd: CaptureFixture[str], mocker: MockerFixture, env: TestEnv):

0 commit comments

Comments
 (0)