testthat works in RStudio but not in docker containers

Hi,

thanks for taking the time to help me. I've been stuck with this problem for couple of days.

I have a package that I have created testthat tests for. When I run them in my own personal computer in RStudio (Ctrl-Shift-T), they run fine and everything is OK.

However, I'm trying to implement these same tests in gitlab CI with docker and just can't get it to work. R CMD check runs fine until the testthat tests. All the test fail and give me an error that a function in my package that Im trying to test cannot be found. Below is an example error message:

test-helper-functions.R:16: error: myOwnFunction results in right number of rows
could not find function "myOwnFunction"
1: .handleSimpleError(function (e)
   {
       handled <<- TRUE
       test_error <<- e
       options(expressions = expressions_opt_new)
       on.exit(options(expressions = expressions_opt), add = TRUE)
       e$expectation_calls <- frame_calls(11, 2)
       test_error <<- e
       register_expectation(e)
       e$handled <- TRUE
       test_error <<- e
   }, "could not find function \"myOwnFunction\"", quote(myOwnFunction(x,
       y, writefile = F))) at /project/tests/testthat/test-helper-functions.R:16
2: eval(code, test_env):

How my gitlab-ci.yml is setup:

 script:
    - R CMD build . --no-build-vignettes --no-manual
    - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
    - R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual

I've checked that my test-* and testthat.R seem to be similar to those of others and like I said run fine in RStudio itself.

testthat.R:

library(testthat)
library(myPackageName)

test_check("myPackageName")

If anyone can help that would be much appreciated. Given how new I am, it is sure to be something stupid.

Do the tests work locally when you call devtools::check() (Ctrl-Shift-E)?