Accessing an artifact from a doctest

I’m using Documenter.doctest(MyPackage; manual=false) inside runtests.jl to run the doctests in my package (as explained here). In one of the doctests, I need to access an artifact. e.g. artifact"myartifact" . I’m getting the following error when I run the tests:

Cannot locate '(Julia)Artifacts.toml' file when attempting to use artifact 'myartifact' in 'Main'

Where do I need to store Artifacts.toml ? Storing it in the package root dir, docs dir or test dir does not seem to work.

Solution by @fredrikekre in Accessing an artifact inside a doctest · Issue #1963 · JuliaDocs/Documenter.jl · GitHub

Easiest (and most common?) way is to expand the macro in your package and only use a regular binding from the outside, e.g.

myartifact = artifact"myartifact"

in your package, and then use

MyPackage.myartifact

from the outside.

The fact that artifact"..." works in the REPL/Main (I think it does?) is mostly for convenience IIRC, but it doesn’t work in arbitrary modules, like the temp ones that are used for doctesting in Documenter.

Is there any other way? I have an artifact that is specific to the docs, which I don’t think makes a lot of sense to download on every package installation.

I am also facing this issue.

I want to use an artifact only for an example in the documentation :

const notebooks_data = joinpath(artifact"spm_notebooks", "spm-notebooks-2a09e1845ad6ec2ec6b9d0ca175cf8aa5d073e81", "data")

const P1 = joinpath(notebooks_data, "T1w.nii")

const P2 = joinpath(notebooks_data, "bold.nii")