Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maxheld83 opened this issue Sep 12, 2024 · 2 comments
Open

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

maxheld83 opened this issue Sep 12, 2024 · 2 comments

Comments

@maxheld83
Copy link
Contributor

maxheld83 commented Sep 12, 2024

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

@asadow
Copy link

asadow commented Sep 23, 2024

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

@maxheld83
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants