From 549bd419bb9a20af4c5c2a1262849d4a9e5bcf22 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sat, 29 Jan 2022 00:06:52 -0800 Subject: [PATCH] use exit hook to remove temp file (#7611) This guarantees the removal will trigger for unexpected early exits --- R-package/tests/testthat/test_dmatrix.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R-package/tests/testthat/test_dmatrix.R b/R-package/tests/testthat/test_dmatrix.R index fc6c4862f..b4f2b6ff3 100644 --- a/R-package/tests/testthat/test_dmatrix.R +++ b/R-package/tests/testthat/test_dmatrix.R @@ -27,6 +27,7 @@ test_that("xgb.DMatrix: saving, loading", { # save to a local file dtest1 <- xgb.DMatrix(test_data, label = test_label) tmp_file <- tempfile('xgb.DMatrix_') + on.exit(unlink(tmp_file)) expect_true(xgb.DMatrix.save(dtest1, tmp_file)) # read from a local file expect_output(dtest3 <- xgb.DMatrix(tmp_file), "entries loaded from") @@ -41,7 +42,6 @@ test_that("xgb.DMatrix: saving, loading", { dtest4 <- xgb.DMatrix(tmp_file, silent = TRUE) expect_equal(dim(dtest4), c(3, 4)) expect_equal(getinfo(dtest4, 'label'), c(0, 1, 0)) - unlink(tmp_file) }) test_that("xgb.DMatrix: getinfo & setinfo", {