# test/Project.toml

**URL:** https://discourse.julialang.org/t/test-project-toml/42868
**Category:** Package Management
**Tags:** pkg
**Created:** [July 10, 2020, 8:23pm UTC](https://discourse.julialang.org/t/test-project-toml/42868 "2020-07-10T20:23:16Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![alan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alan/32/15970_2.png) [@alan](https://discourse.julialang.org/u/alan)
#### Post date: [July 10, 2020, 8:23pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/1 "2020-07-10T20:23:16Z")

</div>

Using Julia 1.4.1, I added `StaticArrays` as a dependency to my project using `add StaticArrays` within Pkg mode. This generated an entry in `Project.toml`. But when I run `test` within Pkg mode, I get a load error saying that StaticArrays is not found in the current path. To fix this, I had to activate `./test` and `add StaticArrays` again, which added an entry in `test/Project.toml`. Is this as expected? I thought `test/Project.toml` was for dependencies that are needed only during testing. In my case, StaticArrays is needed all the time.

It seems unfortunate that I have to add the dependency in both places, because this raises the possibility that I could be testing against one version of `StaticArrays` but using a different version the rest of the time.

Here is the main Project.toml:

```
name = "MatrixCoalescent"
uuid = "e18d61ee-b49e-4354-8047-cdb896e4a8a0"
authors = ["Alan R. Rogers <rogers@anthro.utah.edu> and contributors"]
version = "0.1.0"

[deps]
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]

```

Here is `test/Project.toml`:

```
[deps]
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

```

---

<div class="post-metadata">

### Author: ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)
#### Post date: [July 10, 2020, 8:43pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/2 "2020-07-10T20:43:43Z")

</div>

if from the project directory you do

```julia
Pkg.activate("test")
Pkg.dev(".")

```

Does it fix it for you?

I’ve run into problems with exactly this, so I’m not so sure that this is a solution for you, or the right pattern generally.

---

<div class="post-metadata">

### Author: ![alan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alan/32/15970_2.png) [@alan](https://discourse.julialang.org/u/alan)
#### Post date: [July 10, 2020, 8:50pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/3 "2020-07-10T20:50:26Z")

</div>

Wouldn’t that make a copy of my project in .julia/dev? I’ve never used `dev` before and don’t fully understand what it would do in a case like this, where I’m already in a development directory in which I can edit the code.

---

<div class="post-metadata">

### Author: ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)
#### Post date: [July 10, 2020, 9:02pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/4 "2020-07-10T21:02:50Z")

</div>

No, it shouldn’t do that.

```julia
(@v1.4) pkg> ?dev
  develop [--shared|--local] pkg[=uuid] ...

  Make a package available for development. If pkg is an existing local path, that path will be recorded in the manifest and used. Otherwise, a full git clone of pkg is
  made.

```

---

<div class="post-metadata">

### Author: ![alan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alan/32/15970_2.png) [@alan](https://discourse.julialang.org/u/alan)
#### Post date: [July 10, 2020, 10:19pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/5 "2020-07-10T22:19:34Z")

</div>

I didn’t work. I’m not sure what I’ve done.

```
(@v1.4) pkg> activate .
 Activating environment at `~/src/MatrixCoalescent/Project.toml`

(MatrixCoalescent) pkg> activate test
 Activating environment at `~/src/MatrixCoalescent/test/Project.toml`

(test) pkg> dev .
[ Info: Resolving package identifier `.` as a directory at `~/src/MatrixCoalescent`.
Path `.` exists and looks like the correct package. Using existing path.
  Resolving package versions...
   Updating `~/src/MatrixCoalescent/test/Project.toml`
  [e18d61ee] + MatrixCoalescent v0.1.0 [`..`]
   Updating `~/src/MatrixCoalescent/test/Manifest.toml`
  [e18d61ee] + MatrixCoalescent v0.1.0 [`..`]

(test) pkg> test
ERROR: trying to test unnamed project

(test) pkg> activate .
 Activating environment at `~/src/MatrixCoalescent/Project.toml`
 
(MatrixCoalescent) pkg> test
    Testing MatrixCoalescent
ERROR: can not merge projects

```

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [July 10, 2020, 10:38pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/6 "2020-07-10T22:38:23Z")

</div>

What does your `runtests.jl` file look like? If you have a `using StaticArrays` in it, then you need to have the package loaded in the test environment.

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [July 10, 2020, 10:48pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/7 "2020-07-10T22:48:07Z")

</div>

Also, you can look at Reexport.jl to do `@reexport using StaticArrays` in your module code. If you truly always need StaticArrays this is probably the better plan.

---

<div class="post-metadata">

### Author: ![alan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alan/32/15970_2.png) [@alan](https://discourse.julialang.org/u/alan)
#### Post date: [July 10, 2020, 11:13pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/8 "2020-07-10T23:13:21Z")

</div>

Here is runtests.jl:

```
using MatrixCoalescent
using Test

include("LTriMatrix.jl")

```

LTriMatrix.jl begins with:

```
using Test
include("../src/LTriMatrix.jl")

```

and …/src/LTriMatrix.jl begins with:

```
using StaticArrays

```

So the test always uses StaticArrays. That dependency is listed in the main Project.toml. It surprises me that I need also to list it in test/Project.toml.

---

<div class="post-metadata">

### Author: ![alan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alan/32/15970_2.png) [@alan](https://discourse.julialang.org/u/alan)
#### Post date: [July 10, 2020, 11:21pm UTC](https://discourse.julialang.org/t/test-project-toml/42868/9 "2020-07-10T23:21:05Z")

</div>

Had a look at Reexport.jl, and I suspect it is more than I need. I’m trying to do something very simple: write a unit test (in the test directory) for a file (in the src directory) that has a dependency. Surely Julia can handle that without the need for an external library. No?

Thanks, Alan

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [July 11, 2020, 12:14am UTC](https://discourse.julialang.org/t/test-project-toml/42868/10 "2020-07-11T00:14:13Z")

</div>

That is the same as what I said. So StaticArrays must be in the test environment. If you have to do `using MatrixCoalescent, StaticArrays` in order to get the functionality you want, then StaticArrays must also be in whatever environment you are operating in, even if it is also included in the Project.toml for MatrixCoalescent. In this scenario, it isn’t just a package dependency because you are explicitly using it. For example, if your package also depends on StatsBase, but only for internal functions and nothing from StatsBase directly shows up in your tests, then you don’t need to add StatsBase in test/Project.toml.

The test environment is just like any other environment at this point. So you have to bring into that environment what you plan to use.

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [July 11, 2020, 2:28am UTC](https://discourse.julialang.org/t/test-project-toml/42868/11 "2020-07-11T02:28:20Z")

</div>

> [@tbeason](#):
>
> In this scenario, it isn’t just a package dependency because you are explicitly using it.

This is the correct answer, but it’s a bit unsatisfying for precisely the reason laid out in the OP

> [@alan](#):
>
> It seems unfortunate that I have to add the dependency in both places, because this raises the possibility that I could be testing against one version of `StaticArrays` but using a different version the rest of the time.

One way around this that I’ve found is that you can actually do `using MatrixCoalescent.StaticArrays` in your test file (not 100% sure, but you may have to do this after `using MatrixCoalescent`).

---

<div class="post-metadata">

### Author: ![alan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alan/32/15970_2.png) [@alan](https://discourse.julialang.org/u/alan)
#### Post date: [July 11, 2020, 3:56am UTC](https://discourse.julialang.org/t/test-project-toml/42868/12 "2020-07-11T03:56:36Z")

</div>

Thanks to you all.
