-
Notifications
You must be signed in to change notification settings - Fork 4
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 the default mock path be absolute? #29
Comments
I'd be interested to see what you do to trigger that--I can imagine how it might be possible, but I can't picture the exact workflow that would get you there. |
I created a reprex! 😇 If I run the test in https://github.com/maelle/mockmock/blob/main/tests/testthat/test-blop.R no mock file is created. |
(but if I comment out |
I think a mock file is created, it's just in the
|
I discovered this behavior, that I agree is not that surprising, when writing tests for fledge, a package helping with package development, in which tests we often change the current directory to the directory of a toy package. In fledge tests, using snapshot tests without further customization works since the PR r-lib/testthat#1476 so I wonder whether that could be tweaked in httptest2 too. I don't know exactly how that could happen. The initial current directory could be "recorded" by code stored in the setup/helper file that loads httptest2, and then used throughout the httptest2 calls in the tests. But I agree I can also tweak my tests. |
For the record, in the fledge branch I was working on, library("httptest2")
test_path <- normalizePath(testthat::test_path())
Sys.setenv("fledge.test.path" = test_path)
with_mock_dir <- function(name, ...) {
dir <- file.path(dirname(Sys.getenv("fledge.test.path")), "fixtures", name)
httptest2::with_mock_dir(dir, ...)
} |
Sorry in advance for not writing a proper reprex! I might come to this later. 😇
I think my current problem is similar to r-lib/testthat#1476 in testthat.
When changing the current directory in a test, then using say
httptest2::with_mock_dir()
, nothing gets recorded in the actual package. I think it's becausehttptest2:::default_mock_path()
is relative to the current directory.The text was updated successfully, but these errors were encountered: