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

Should snapshot_accept() succeed from within tests/? #1485

Closed
MichaelChirico opened this issue Nov 9, 2021 · 6 comments
Closed

Should snapshot_accept() succeed from within tests/? #1485

MichaelChirico opened this issue Nov 9, 2021 · 6 comments

Comments

@MichaelChirico
Copy link
Contributor

I sometimes run tests like

setwd('tests')
source('testthat.R')

However, this conflicts with using snapshot tests; after the output updated, I was instructed to run snapshot_accept(...), but this failed:

snapshot_accept(...)
No snapshots to update

However, it did create the temp (.new) file, and succeeded like so:

setwd('..')
snapshot_accept(...)
Updating snapshots:
* ...
@hadley
Copy link
Member

hadley commented Dec 20, 2021

This feels like a sufficiently unusual workflow that we're unlikely to work on it, but I'd review a PR for it.

@hadley hadley closed this as completed Dec 20, 2021
@MichaelChirico
Copy link
Contributor Author

ran into this again 😅

@MichaelChirico
Copy link
Contributor Author

MichaelChirico commented Oct 24, 2023

Now noticed snapshot_accept() has a path argument that I could change to testthat from the default tests/testthat.

I think what's most confusing here is the misleading message:

* Run `testthat::snapshot_accept('$DIR')` to accept the change.
* Run `testthat::snapshot_review('$DIR')` to interactively review the change.

Would adding "Run snapshot*() from the package directory to ..." be too distracting for the default use case?

@hadley
Copy link
Member

hadley commented Oct 24, 2023

Yeah, I think so.

Are you changing the path with code? (e.g. with withr::local_dir())?

@MichaelChirico
Copy link
Contributor Author

MichaelChirico commented Oct 24, 2023

no. workflow is

  • start R in package dir
  • setwd("tests") (is that considered "with code"?)
  • source("testthat.R")

I find that's the easiest way to run basically as R CMD check does without needing to memorize anything like whether it's test_dir()/test_check()/check_package()/test_package().

@hadley
Copy link
Member

hadley commented Oct 24, 2023

Ah yeah, in that case I'd just case you have an unusual workflow and you're on your own.

You could make life a little easier on yourself by running source("tests/testhat.R", chdir = TRUE)

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