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

Check that the tests don't change the global state #388

Closed
2 of 11 tasks
IndrajeetPatil opened this issue Oct 11, 2023 · 0 comments · Fixed by easystats/insight#829
Closed
2 of 11 tasks

Check that the tests don't change the global state #388

IndrajeetPatil opened this issue Oct 11, 2023 · 0 comments · Fixed by easystats/insight#829
Assignees
Labels
Beginner-friendly 🤝 Friendly for new contributors Code Style 👩‍💻 Core Packages 📦 Discussion and planning about core packages of easystats Low priority 😴 This issue does not impact package functionality much

Comments

@IndrajeetPatil
Copy link
Member

IndrajeetPatil commented Oct 11, 2023

Tests shouldn't change the R landscape, and testthat can't always do this clean-up for you. So we can check ourselves that we are writing self-contained tests.

To make sure that the tests aren't changing the global state, add the following to tests/testthat/helper-state.R:

testthat::set_state_inspector(function() {
  list(
    attached = search(),
    connections = nrow(showConnections()),
    cwd = getwd(),
    envvars = Sys.getenv(),
    libpaths = .libPaths(),
    locale = Sys.getlocale(),
    options = .Options,
    packages = .packages(all.available = TRUE),
    NULL
  )
})

If a test is changing the global state, it will produce warnings and the check-test-warnings workflow will fail.

To know more about how set_state_inspector() works, read the package docs.

Progress tracker:

  • insight
  • modelbased
  • bayestestR
  • effectsize
  • parameters
  • performance
  • correlation
  • report
  • see
  • datawizard
  • easystats
@IndrajeetPatil IndrajeetPatil added Core Packages 📦 Discussion and planning about core packages of easystats Code Style 👩‍💻 Low priority 😴 This issue does not impact package functionality much Beginner-friendly 🤝 Friendly for new contributors labels Oct 11, 2023
strengejacke added a commit to easystats/insight that referenced this issue Nov 2, 2023
strengejacke added a commit to easystats/insight that referenced this issue Nov 13, 2023
* Use withr to not change global state
Fixes easystats/easystats#388

* test

* fix test

* fix test

* fix

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Beginner-friendly 🤝 Friendly for new contributors Code Style 👩‍💻 Core Packages 📦 Discussion and planning about core packages of easystats Low priority 😴 This issue does not impact package functionality much
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants