@@ -225,44 +225,41 @@ def test_log_artifact_type_model_when_dvc_add_fails(tmp_dir, mocker, mocked_dvc_
225
225
}
226
226
227
227
228
- def test_log_artifact_inside_exp (tmp_dir , mocked_dvc_repo ):
229
- data = tmp_dir / "data"
230
- data .touch ()
231
- with Live () as live :
232
- live ._inside_dvc_exp = True
233
- live .log_artifact ("data" )
234
- mocked_dvc_repo .add .assert_not_called ()
235
-
236
-
237
228
@pytest .mark .parametrize ("tracked" , ["data_source" , "stage" , None ])
238
- def test_log_artifact_inside_exp_logger (tmp_dir , mocker , dvc_repo , tracked ):
229
+ def test_log_artifact_inside_exp (tmp_dir , mocker , dvc_repo , tracked ):
239
230
logger = mocker .patch ("dvclive.live.logger" )
231
+ data = tmp_dir / "data"
232
+ data .touch ()
240
233
if tracked == "data_source" :
241
- data = tmp_dir / "data"
242
- data .touch ()
243
234
dvc_repo .add (data )
244
235
elif tracked == "stage" :
245
236
dvcyaml_path = tmp_dir / "dvc.yaml"
246
237
with open (dvcyaml_path , "w" ) as f :
247
238
f .write (dvcyaml )
248
- with Live () as live :
249
- live ._inside_dvc_exp = True
250
- live .log_artifact ("data" )
251
- msg = "Skipping dvc add data because `dvc exp run` is running."
252
- if tracked == "data_source" :
253
- msg += (
254
- "\n To track it automatically during `dvc exp run`:"
239
+ live = Live ()
240
+ spy = mocker .spy (live ._dvc_repo , "add" )
241
+ live ._inside_dvc_exp = True
242
+ live .log_artifact ("data" )
243
+ if tracked == "stage" :
244
+ msg = (
245
+ "Skipping `dvc add data` because it is already being tracked"
246
+ " automatically as an output of `dvc exp run`."
247
+ )
248
+ logger .info .assert_called_with (msg )
249
+ spy .assert_not_called ()
250
+ elif tracked == "data_source" :
251
+ msg = (
252
+ "\n To track 'data' automatically during `dvc exp run`:"
255
253
"\n 1. Run `dvc exp remove data.dvc` "
256
254
"to stop tracking it outside the pipeline."
257
255
"\n 2. Add it as an output of the pipeline stage."
258
256
)
259
257
logger .warning .assert_called_with (msg )
260
- elif tracked == "stage" :
261
- msg += "\n It is already being tracked automatically."
262
- logger .info .assert_called_with (msg )
258
+ spy .assert_called_once ()
263
259
else :
264
- msg + = (
265
- "\n To track it automatically during `dvc exp run`, "
260
+ msg = (
261
+ "\n To track 'data' automatically during `dvc exp run`, "
266
262
"add it as an output of the pipeline stage."
267
263
)
268
264
logger .warning .assert_called_with (msg )
265
+ spy .assert_called_once ()
0 commit comments