Skip to content

add helper to skip tests when some pkg is pkgload::load_all()dΒ #391

@maxheld83

Description

@maxheld83

TL,DR: I have a skip_if_installed_but_not_via_loadall(x = "my-in-dev-package") helper, which helps me reduce the load_all()/installed package confusion: https://github.com/dataheld/elf/blob/main/R/installed.R

I'd be happy to contribute it, if you find it useful as a stop-gap until #310 etc.


as I imagine some people who develop shiny apps as functions inside R packages, I kept shooting myself in the foot with this:

shinytest2 requires that your package to be installed when testing. testthat::test_local() (and related wrappers) eventually call pkgload::load_all() to temporarily source the local R package. You can use test_local() to test non-shinytest2 tests, but you will need to install your R package to safely execute your shinytest2 tests. If not installed, it will create a confusing situation where your shinytest2 tests are running on a different version of your R package (whichever was last installed), than the rest of your tests (the current source).

(as in, I confuse myself by running tests on the wrong version).

As a stop-gap, I've built myself a set of helpers to automatically skip (shinytest2) tests, whenever the package in question is currently (ie. when running the test) available via pkgload::load_all().
This forces me to install the current version and then run testthat::test_package(package = "mypkg", load_package = 'installed').
Even if I forget to install, test_package() I at least get the tests at the same version as the actual shiny app running.

The helpers to detect whether some package is currently load_all()d live here:
They're just wrappers around pkgload::is_dev_package().

The downside is that I have to provide a version of this for every package I built, since I couldn't figure out a way to find that name automatically.

(I also tried automatically figuring out all the used packages in an expression, and then looping over those to skip if any of them where load_all()d, but I couldn't make that work).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions