Skip to content

Update vignette advice for migrating to {testthat} 3e #2080

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jdblischak
Copy link
Contributor

I have recently been working on migrating some packages from {testthat} 2e to 3e. This PR updates a few places in the vignettes where I got confused.

First is the behavior of expect_equal(ignore_attr = TRUE). From what I can decipher from the history, this initially ignored the attribute names. However, now it appears to ignore all attributes just like expect_equivalent(). I'm not sure exactly when this change occurred since this functionality was migrated to {waldo}.

library("testthat")
packageVersion("testthat")
## [1] ‘3.2.3.9000’
edition_get()
## [1] 3

x1 <- x2 <- mtcars
colnames(x2) <- NULL
expect_equivalent(x1, x2)
## Warning message:
##   `expect_equivalent()` was deprecated in the 3rd edition.
## ℹ Use expect_equal(ignore_attr = TRUE)
expect_equal(x1, x2)
## Error: `x1` (`actual`) not equal to `x2` (`expected`).
##
## `names(actual)` is a character vector ('mpg', 'cyl', 'disp', 'hp', 'drat', ...)
## `names(expected)` is absent
expect_equal(x1, x2, ignore_attr = TRUE)

xref: #1241, #1422, r-lib/waldo#97

Second is the advice for interactive debugging when the tests are configured to run in parallel. I wasn't able to use browser() with CheckReporter because it still ran the tests in parallel. I was able to use browser() with the DebugReporter.

# Added browser() to first test in test-expect-condition.R

# CheckReporter
devtools::test(filter = "expect", reporter = "check")
## ℹ Testing testthat
## Starting 8 test processes
## [ FAIL 1 | WARN 0 | SKIP 1 | PASS 519 ]
## 
## ══ Skipped tests (1) ══════════════════════════════════════════════════════════════════════════════
## • On Windows (1): test-expect-known.R:46:3
## 
## ══ Failed tests ═══════════════════════════════════════════════════════════════════════════════════
## ── Error (test-expect-condition.R:2:3): returns condition or value ────────────────────────────────
## Error in `eval(code, test_env)`: non-interactive browser() -- left over from debugging?
## 
## [ FAIL 1 | WARN 0 | SKIP 1 | PASS 519 ]

# DebugReporter
devtools::test(filter = "expect", reporter = "debug")
## ℹ Testing testthat
## Called from: eval(code, test_env)
Browse[1]> 
```

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.

1 participant