From 5da55c9fc3b2e93ee09a212d6b0d73c0efd3529f Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 1 Apr 2024 10:16:08 -0700 Subject: [PATCH] better test cleanup --- tests/testthat/test-phantom_loading.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-phantom_loading.R b/tests/testthat/test-phantom_loading.R index 1776282..4b2a17a 100644 --- a/tests/testthat/test-phantom_loading.R +++ b/tests/testthat/test-phantom_loading.R @@ -6,6 +6,11 @@ testthat::test_that( "extdata", "tests", "subsetCars.Rmd", package = "DataPackageR" ) pkg_name <- "mtcars20" + on.exit( + if (pkg_name %in% devtools::package_info('attached')$package){ + devtools::unload(pkg_name) + } + ) # remove this directory on exit temp_dir <- withr::local_tempdir() pkg_path <- file.path(temp_dir, pkg_name) @@ -31,9 +36,5 @@ testthat::test_that( expect_false( res2 <- pkg_name %in% devtools::package_info('attached')$package ) - - # reset and verify attachment state - if (res2) devtools::unload(pkg_name) - expect_false(pkg_name %in% devtools::package_info('attached')$package) } )