Skip to content

S4 methods not registered for packages loaded in test file #1556

@kevinushey

Description

@kevinushey

(I apologize in advance...)

Normally, loading the Matrix package forces a generic for t to be registered; e.g.

library(Matrix)
inherits(t, "standardGeneric")  # TRUE

However, this doesn't seem to happen if the package is loaded in a test file. For example:

library(Matrix)
test_that("t is a standardGeneric", {
  expect_s4_class(t, "standardGeneric")
})

If I run testthat::test_local(), I see:

> testthat::test_local()
✔ | F W S  OK | Context
✖ | 1       0 | hello
─────────────────────────────────────────────────────────
Failure (test-hello.R:4:3): t is a standardGeneric
`t` is not an S4 object
─────────────────────────────────────────────────────────

══ Results ══════════════════════════════════════════════
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
Error: Test failures

And yet, this works fine with test_file():

> testthat::test_file("tests/testthat/test-hello.R")

══ Testing test-hello.R ═════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ] Done!

Any idea what might be going on?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions