JuliaDocs / Documenter.jl

A documentation generator for Julia.

Home Page:https://documenter.juliadocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Separate jldoctest environments

simonmandlik opened this issue · comments

Hello everyone,
in jldoctests I want to demonstrate two possible extensions for function TestPkg.f

module TestPkg

"""
```jldoctest env1; output=false
function TestPkg.f()
    1
end

# output

```
```jldoctest env1
julia> TestPkg.f()
1
```

```jldoctest env2; output=false
function TestPkg.f()
    2
end

# output

```
```jldoctest env2
julia> TestPkg.f()
2
```
"""
function f end

end

Even if I use separate jldoctest “environments” env1 and env2, it fails as the function is being overloaded twice:

│ Expected output:
│   diff = WARNING: Method definition f() in module __doctest__named__env1 at none:1 overwritten in module Main on the same line (check for duplicate calls to `include`).

This wasn’t happening in julia v1.9.4, but is breaking my builds in v1.10. Is there a recommended way to achieve this?

Thanks!

Modifying a global module in a doctest is a bit iffy, since it will, by definition, leak into other doctests. It just looks like Julia is now printing a new warning in this case in 1.10. As a workaround, you could have a doctest setup that defines a new TestPkg module every time that just emulates the global module. But it depends a bit on what the exact real use case here is.

I suppose ideally we'd somehow magically roll back the global changes after each doctest block, but I think that's not particularly easy to do.