Skip to content

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

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).

Activity

  1. asadow commented on Sep 23, 2024

    @asadow

    Are you sure you want to go the package route? I use rhino and don't have to worry about any of this.

  2. maxheld83 commented on Sep 23, 2024

    @maxheld83
    ContributorAuthor

    Are you sure you want to go the package route? I use rhino and don't have to worry about any of this.

    thanks for the kind pointer @asadow; I haven't used rhino/box.
    I like to keep my stuff simple, and so I use the package infra for everything.

    This is probably not the right place to discuss the pros/cons of shiny apps inside packages, right?

  3. schloerke commented on Feb 11, 2025

    @schloerke
    Collaborator

    @maxheld83 If this worked with your local R package needing to be installed, would you still need this feature?

  4. maxheld83 commented on Feb 11, 2025

    @maxheld83
    ContributorAuthor

    @schloerke sorry, not sure I understand.

    Do you mean:

    If this worked without your local R package needing to be installed, would you still need this feature?

    (emphasis marks correction)

    Then yes, I would not need this feature, if shinytest2 always used the the same version of testthat (~ devtools::load_all()).

    I always thought of this as a workaround until #310, so if that's even somewhere on the horizon/still planned, I'd say the (probably marginal) of this workaround/feature does not warrant the extra weight.

  5. schloerke commented on Feb 12, 2025

    @schloerke
    Collaborator

    😂 Yes. without. 🤦🤦🤦

    I'm hopeful #402 will address this. 🤞

  6. maxheld83 commented on Feb 13, 2025

    @maxheld83
    ContributorAuthor

    I suppose this can be closed then 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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