Skip to content

Tests fail unless I add source('setup.R') data to test file #1964

@mduncans

Description

@mduncans

I have several tests that use data from setup.R stored in an environment setup_data. All but two of my tests pass, but the two that fail give the error that object 'setup_data' not found. If I add a source('setup.R') call above the test file that contains the tests that fail, they pass instead. The test below is one example along with the message after running test().

test_that('make_contrast_predicitons warns when less than two concentration measurements are given', {
  expect_warning(
    make_contrast_predictions(
      setup_data$qt_mod,
      setup_data$data_qt_proc$CONC[[1]],
      setup_data$data_qt_proc$deltaQTCF,
      a_list = list(CONC = 10, deltaQTCFBL = 0)))
})

Output:

> test_active_file()
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
── Error (test-make_contrast_predictions.R:10:3): make_contrast_predicitons warns when less than two concentration measurements are given ──
Error in `eval(Call$data, env)`: object 'setup_data' not found
Backtrace:
    ▆
 1. ├─testthat::expect_warning(...) at test-make_contrast_predictions.R:10:3
 2. │ └─testthat:::expect_condition_matching(...)
 3. │   └─testthat:::quasi_capture(...)
 4. │     ├─testthat (local) .capture(...)
 5. │     │ └─base::withCallingHandlers(...)
 6. │     └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
 7. └─QTctoolkit::make_contrast_predictions(...)
 8.   └─base::lapply(...) at internal/R/QTc-computation-functions.R:370:3
 9.     └─QTctoolkit (local) FUN(X[[i]], ...)
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]

I can add the call to the function before the test and get the expected warning:

test_that('make_contrast_predicitons warns when less than two concentration measurements are given', {
  make_contrast_predictions(
    setup_data$qt_mod,
    setup_data$data_qt_proc$CONC[[1]],
    setup_data$data_qt_proc$deltaQTCF,
    a_list = list(CONC = 10, deltaQTCFBL = 0))
  expect_warning(
    make_contrast_predictions(
      setup_data$qt_mod,
      setup_data$data_qt_proc$CONC[[1]],
      setup_data$data_qt_proc$deltaQTCF,
      a_list = list(CONC = 10, deltaQTCFBL = 0)))
})

Output:

Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
[ FAIL 1 | WARN 1 | SKIP 0 | PASS 0 ]

── Warning (test-make_contrast_predictions.R:10:3): make_contrast_predicitons warns when less than two concentration measurements are given ──
CONC vector contains less than 2 measurements
Backtrace:
    ▆
 1. └─QTctoolkit::make_contrast_predictions(...) at test-make_contrast_predictions.R:10:3

── Error (test-make_contrast_predictions.R:10:3): make_contrast_predicitons warns when less than two concentration measurements are given ──
Error in `eval(Call$data, env)`: object 'setup_data' not found
Backtrace:
    ▆
 1. └─QTctoolkit::make_contrast_predictions(...) at test-make_contrast_predictions.R:10:3
 2.   └─base::lapply(...) at internal/R/QTc-computation-functions.R:370:3
 3.     └─QTctoolkit (local) FUN(X[[i]], ...)
[ FAIL 1 | WARN 1 | SKIP 0 | PASS 0 ]

Adding source('setup.R') to my test causes the test to pass.

source('setup.R')

test_that('make_contrast_predicitons does not run when less than two concentration measurements are given', {
  expect_warning(
    make_contrast_predictions(
      setup_data$qt_mod,
      setup_data$data_qt_proc$CONC[[1]],
      setup_data$data_qt_proc$deltaQTCF,
      a_list = list(CONC = 10, deltaQTCFBL = 0)))
})

Output:

Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 0 ]Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
Joining with `by = join_by(ID)`
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    reprexneeds a minimal reproducible example

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions