Documenter.jl icon indicating copy to clipboard operation
Documenter.jl copied to clipboard

Make doctest runnable inside @testitem

Open schlichtanders opened this issue 2 months ago • 1 comments

I am unable to make doctset runnable inside @testitem

@testitem "Doctests (Documenter.jl)" begin
    using MyPackage
    using Documenter
    DocMeta.setdocmeta!(MyPackage, :DocTestSetup, :(using MyPackage); recursive=true)
    doctest(MyPackage)
end

fails with

┌ Error: Failed to evaluate `CurrentModule = MyPackage` in `@meta` block.
│   exception =
│    UndefVarError: `MyPackage` not defined in `Main`
│    Suggestion: check for spelling errors or missing imports.
│    Hint: MyPackage is loaded but not imported in the active module Main.
└ @ Documenter ~/.julia/packages/Documenter/HdXI4/src/utilities/utilities.jl:47

schlichtanders avatar Oct 28 '25 19:10 schlichtanders

Hmm this is an interesting point. All meta blocks are eval'ed into Main by default, so if Main doesn't have the modules you need, it's not going to work.

A monkeypatch would be to add an @eval Main import MyPackage into your test item, which should get it to work, but a 'cleaner' solution will need some more thought.

asinghvi17 avatar Oct 28 '25 20:10 asinghvi17