# Accessing an artifact from a doctest

**URL:** <https://discourse.julialang.org/t/accessing-an-artifact-from-a-doctest/88392>\
**Category:** General Usage\
**Tags:** testing\
**Created:** [October 7, 2022, 10:46am UTC](https://discourse.julialang.org/t/accessing-an-artifact-from-a-doctest/88392 "2022-10-07T10:46:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mroavi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mroavi/32/8804_2.png) [@mroavi](https://discourse.julialang.org/u/mroavi)\
**Post date:** [October 7, 2022, 10:46am UTC](https://discourse.julialang.org/t/accessing-an-artifact-from-a-doctest/88392/1 "2022-10-07T10:46:28Z")

</div>

I’m using `Documenter.doctest(MyPackage; manual=false)` inside `runtests.jl` to run the doctests in my package (as explained [here](https://juliadocs.github.io/Documenter.jl/stable/man/doctests/#Doctesting-as-Part-of-Testing)). 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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![mroavi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mroavi/32/8804_2.png) [@mroavi](https://discourse.julialang.org/u/mroavi)\
**Post date:** [October 7, 2022, 11:48am UTC](https://discourse.julialang.org/t/accessing-an-artifact-from-a-doctest/88392/2 "2022-10-07T11:48:37Z")

</div>

Solution by @fredrikekre in [Accessing an artifact inside a doctest · Issue #1963 · JuliaDocs/Documenter.jl · GitHub](https://github.com/JuliaDocs/Documenter.jl/issues/1963)

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

```julia
myartifact = artifact"myartifact"

```

in your package, and then use

```julia
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.

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [November 27, 2022, 11:23am UTC](https://discourse.julialang.org/t/accessing-an-artifact-from-a-doctest/88392/3 "2022-11-27T11:23:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aTrotier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atrotier/32/32165_2.png) [@aTrotier](https://discourse.julialang.org/u/aTrotier)\
**Post date:** [September 1, 2023, 12:40pm UTC](https://discourse.julialang.org/t/accessing-an-artifact-from-a-doctest/88392/4 "2023-09-01T12:40:35Z")

</div>

I am also facing this issue.

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

```julia
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")

```
