| CleanupReporter {ps} | R Documentation |
testthat reporter that checks if child processes are cleaned up in tests
Description
CleanupReporter takes an existing testthat Reporter object, and
wraps it, so it checks for leftover child processes, at the specified
place, see the proc_unit argument below.
Usage
CleanupReporter(reporter = testthat::ProgressReporter)
Arguments
reporter |
A testthat reporter to wrap into a new |
Details
Child processes can be reported via a failed expectation, cleaned up silently, or cleaned up and reported (the default).
The constructor of the CleanupReporter class has options:
-
file: the output file, if any, this is passed toreporter. -
proc_unit: when to perform the child process check and cleanup. Possible values:-
"test": at the end of eachtestthat::test_that()block (the default), -
"testsuite": at the end of the test suite.
-
-
proc_cleanup: Logical scalar, whether to kill the leftover processes,TRUEby default. -
proc_fail: Whether to create an expectation, that fails if there are any processes alive,TRUEby default. -
proc_timeout: How long to wait for the processes to quit. This is sometimes needed, because even if some kill signals were sent to child processes, it might take a short time for these to take effect. It defaults to one second. -
rconn_unit: When to perform the R connection cleanup. Possible values are"test"and"testsuite", like forproc_unit. -
rconn_cleanup: Logical scalar, whether to clean up leftover R connections.TRUEby default. -
rconn_fail: Whether to fail for leftover R connections.TRUEby default. -
file_unit: When to check for open files. Possible values are"test"and"testsuite", like forproc_unit. -
file_fail: Whether to fail for leftover open files.TRUEby default. -
conn_unit: When to check for open network connections. Possible values are"test"and"testsuite", like forproc_unit. -
conn_fail: Whether to fail for leftover network connections.TRUEby default.
Value
New reporter class that behaves exactly like reporter,
but it checks for, and optionally cleans up child processes, at the
specified granularity.
Examples
This is how to use this reporter in testthat.R:
library(testthat)
library(mypackage)
if (ps::ps_is_supported()) {
reporter <- ps::CleanupReporter(testthat::ProgressReporter)$new(
proc_unit = "test", proc_cleanup = TRUE)
} else {
## ps does not support this platform
reporter <- "progress"
}
test_check("mypackage", reporter = reporter)
Note
Some IDEs, like RStudio, start child processes frequently, and
sometimes crash when these are killed, only use this reporter in a
terminal session. In particular, you can always use it in the
idiomatic testthat.R file, that calls test_check() during
R CMD check.