Skip to content

Set .__DEVTOOLS__ marker so testthat::with_mocked_bindings() works with loadfast#12

Merged
ak-finccam merged 2 commits into
mainfrom
copilot/investigate-with-mocked-bindings-issue
Apr 14, 2026
Merged

Set .__DEVTOOLS__ marker so testthat::with_mocked_bindings() works with loadfast#12
ak-finccam merged 2 commits into
mainfrom
copilot/investigate-with-mocked-bindings-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

testthat::with_mocked_bindings() auto-detects the active dev package via pkgload::dev_meta(), which looks for a .__DEVTOOLS__ environment in the namespace. loadfast wasn't setting this marker, causing the error "No packages loaded with pkgload".

Changes

  • R/loadfast.R: Add ns_env[[".__DEVTOOLS__"]] <- new.env(parent = ns_env) during full load namespace setup — mirrors what pkgload::create_dev_meta() does. The marker persists through incremental reloads since the namespace env is reused.
  • test_loadfast.R: Three new Stage 1 checks — .__DEVTOOLS__ is set, pkgload::dev_meta() returns non-NULL, and with_mocked_bindings() works both with and without explicit .package.

After this change:

load_fast("mypkg")

# Previously errored with "No packages loaded with pkgload"
testthat::with_mocked_bindings(
  some_function(),
  dependency = function(...) "mocked"
)

Copilot AI linked an issue Apr 14, 2026 that may be closed by this pull request
…th loadfast

Agent-Logs-Url: https://github.com/finccam/loadfast/sessions/8e755081-78be-4f0d-a46f-bf749eb3bffb

Co-authored-by: ak-finccam <266784444+ak-finccam@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate cannot use testthat::with_mocked_bindings() issue Set .__DEVTOOLS__ marker so testthat::with_mocked_bindings() works with loadfast Apr 14, 2026
Copilot AI requested a review from ak-finccam April 14, 2026 14:51
@ak-finccam ak-finccam marked this pull request as ready for review April 14, 2026 14:55
@ak-finccam
Copy link
Copy Markdown
Contributor

@felix-andreas-finccam Bisher hat testthat::with_mocked_bindings() nicht mit loadfast geklappt. Das hier behebt das mit minimalem Aufwand.

@ak-finccam ak-finccam merged commit 1c917f3 into main Apr 14, 2026
2 checks passed
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

Successfully merging this pull request may close these issues.

Cannot use testthat::with_mocked_bindings()

3 participants