Skip to content

Inconsistency between testthat::test_file() and devtools::test() with helpers and environment variables #2613

@DanChaltiel

Description

@DanChaltiel

Hi,

I'm using is_testing() in my helpers files to load some objects on load_all(), but not during tests.
This is very convenient in my field of work.

However, tests behave differently in RStudio when using the "Test" button in the Build pane, which seems to run devtools::test(), and the "Run tests" button in the source pane, which seems to run testthat::test_file():

  • For devtools::test(), is_testing() is FALSE inside the helper
  • For testthat::test_file(), is is TRUE

I'm posting this issue here because IMHO, testthat is right here (we are currently running tests).

I have up-to-date RStudio, devtools, and testthat (as per CRAN).

Minimal reproducible example

#in tests/testthat/test-poc.R  
test_that("devtools POC", {  
  expect_true(is_testing())  
})  

test_that("devtools POC2", {  
  expect_true(it)  
})  

#in tests/testthat/helper-poc.R  
it = is_testing()

Tests :

> testthat::test_file("tests/testthat/test-poc.R")
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 2 ]> 

> devtools::test()
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 1 ]

── Failure (test-poc.R:6:3): devtools POC2 ────────────────────────────────────────────────────────────────────────
`it` is not TRUE

`actual`:   FALSE
`expected`: TRUE 
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 1 ]

Thank you for your work on this package!

PS: In a more complex project, unfortunately not reprexable, I had even discrepancies inside devtools, with all tests passing with devtools::test() but failing with devtools::test_active_file().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions