testthat fails within devtools::check but works in devtools::test

I know this issue has been bouncing round the forums for some years but I still can't find a solution.

devtools::test() works

> devtools::test()
Loading ds.anomlr
All rights reserved (c) 2018-2019 Senseon Tech Ltd
Testing ds.anomlr
√ |  OK F W S | Context
√ | 100       | Large data (v1.0.4) unit tests [19.0 s]
√ |   6       | Pipelines (v1.0.4) unit tests [0.1 s]
√ |  16       | prep (v1.0.4) unit tests [0.2 s]
√ |   4       | sim (v1.0.4) unit tests [0.1 s]
√ |  32       | svd (v1.0.4) unit tests [0.2 s]
√ |   9       | T1 (v1.0.4) unit tests [0.2 s]

== Results =====================================================================
Duration: 19.9 s

OK:       167
Failed:   0
Warnings: 0
Skipped:  0

But devtools::check() fails

-- Test failures ------------------------------------------------------------------------------ testthat ----

> library(testthat)
> library(ds.anomlr)
All rights reserved (c) 2018-2019 Senseon Tech Ltd

Attaching package: 'ds.anomlr'

> 
> test_check("ds.anomlr")
-- 1. Error: (unknown) (@test-large.R#12)  ------------------------------------------------------------------
cannot open the connection
1: readRDS(here("tests", "testthat", "test_data", filename)) at testthat/test-large.R:12
2: gzfile(file, "rb")

== testthat results  ========================================================================================
OK: 67 SKIPPED: 0 WARNINGS: 1 FAILED: 1
1. Error: (unknown) (@test-large.R#12) 

Error: testthat unit tests failed
Execution halted

1 error x | 2 warnings x | 2 notes x

Any help resolving this appreciated.

1 Like

The issue in this case seems to be where to put the test data so that devtools::check can also find it?

1 Like

Solved. I this case I had started using here::here as it claimed to be a safer drop-in for file.path, but it gets the test environment paths confused. Not using here solved this problem.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.