Optional testing files in pacakge?

Hello, I have made a small package for reading and writing a particular file type, and I would like to provide some sample testing files to run unit tests on. However, it seems suboptimal to have them downloaded with the package since most users don’t need them. Is there a way to mark some files to only be downloaded for running tests?

Ideally I would like to avoid making a new repo just to host the files to be downloaded with Artifacts, but I will if there’s no better way.

Any help or ideas will be appreciated!

Artifacts can be lazily downloaded (on-demand) by setting lazy = true in your Artifacts.toml file like so:

[socrates]
git-tree-sha1 = "43563e7631a7eafae1f9f8d9d332e3de44ad7239"
lazy = true

It is recommended to keep tests in a separate test/ directory with its own environment (separate Project.toml). This will allow you to avoid adding test-specific dependencies into your actual package:

- Project.toml
- src/
   - main.jl
- test/
    - Project.toml
    - tests.jl

I have a similar file reading package that I recently switched to Artifacts for test files: C3D.jl.

I used ArtifactUtils.jl to create the artifacts as gists on GitHub, and then use LazyArtifacts (stdlib) in my tests to download the individual artifacts on demand.

1 Like