Skip to content

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]> 
```

``` r
devtools::test(filter = "badtest", reporter = "check")
```
If you want to use `cat()` or `message()` for print-debugging test cases, then the best is to temporarily run tests sequentially, by changing the `Config` entry in `DESCRIPTION` or setting `Sys.setenv(TESTTHAT_PARALLEL = "false")`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced this with a technique I just learned about.

@hadley hadley merged commit 6dd8896 into r-lib:main Jul 23, 2025
13 checks passed
@hadley
Copy link
Member

hadley commented Jul 23, 2025

Thank you!

@jdblischak jdblischak deleted the update-3e-vignettes branch July 23, 2025 18:18
schloerke added a commit to schloerke/testthat that referenced this pull request Jul 25, 2025
* upstream/HEAD: (250 commits)
  Implement `expect_shape()` (r-lib#1469)
  Re-enable catch tests on windows (r-lib#2104)
  Move digest to suggests (r-lib#2105)
  Support emscripten in `skip_on_os()` (r-lib#2103)
  Add `skip_unless_r()` (r-lib#2094)
  Require R 4.1 (r-lib#2101)
  Allow unquoting first arg for `expect_s4_class()` (r-lib#2065)
  typo fix (r-lib#2051)
  Explicitly pass `parent.frame()` in `it()` (r-lib#2086)
  Update vignette advice for migrating to {testthat} 3e (r-lib#2080)
  New praise messages (r-lib#1974)
  move '!' outside aggregation (r-lib#2067)
  Handle deprecation of std::uncaught_exception() (r-lib#2097)
  perf: use `anyNA()` (r-lib#2058)
  Upkeep (r-lib#2099)
  Implement `mock_output_sequence()` (r-lib#2061)
  Increment version number to 3.2.3.9000
  Increment version number to 3.2.3
  Update CRAN comments
  Finish off r-lib#2046
  ...
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.

2 participants