Skip to content

Commit

Permalink
better test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
slager committed Apr 1, 2024
1 parent 589cedb commit 5da55c9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/testthat/test-phantom_loading.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
)

0 comments on commit 5da55c9

Please sign in to comment.