Skip to content

RStudio reports that that symbols in unit tests are out of scopeΒ #2223

@jamesfowkes

Description

@jamesfowkes

I'm new to R and just started with testthat, using it to run tests again a package I'm writing. My tests themselves run fine, but RStudio is yellow-squiggle underlining all the functions from both testthat and my package with the message no symbol named 'expect_true' in scope for example (example image below).

A screenshot from RStudio showing some functions underlined with yellow squiggles and a tooltip saying no symbol named 'expect_true' in scope and no symbol named 'is_valid_time' in scope

This is really annoying and I have a "no warnings" mindset when it comes to code so I would like to fix them properly without affecting "genuine" warnings in the tests. I am aware of the RStudio "Warn if variable used has no definition in scope" option but would prefer not to disable it.

I have I already tried:

  1. Adding a .lintr file to the package root:
linters: with_defaults(
  object_usage_linter = NULL
)
exclusions: list("tests/testthat")
  1. Confirming that both testthat and my package are in tests/testthat.R:
library(MyPackage)
test_check("MyPackage")

3 Adding export(is_valid_time) to the NAMESPACE file at the package root, which would not solve the testthat calls, but I thought might at least solve the calls into my package functions.

None of these changed the RStudio behaviour (I restarted RStudio to make sure it picked up these changes).

I realise this could be an issue/question more about RStudio than testthat itself, but I'm guessing the problem is that testthat does imports in a way that RStudio can't pick up on or something similar. So I thought this might be the best place to ask.

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