# LoadError: UndefVarError: include not defined when using Pkg.test

**URL:** <https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084>\
**Category:** General Usage\
**Created:** [September 13, 2021, 10:08am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084 "2021-09-13T10:08:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [September 13, 2021, 10:08am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084/1 "2021-09-13T10:08:16Z")

</div>

Hello, I want to create a package A with different modules, A and Aux, and test them using pkg.test. The project structure is as follows:

```julia
#src/A.jl
include("aux.jl")
module A
export f
f(x)=x^2
end

```

```julia
#src/Aux.jl
module Aux
export g
g(x) = x+1
end

```

```julia
#test/runtests.jl
using Test, A, Aux
@test f(0)==0
@test g(0)==1

```

Now, if I activate my environment and test using

```julia
]> test

```

I get a

> ERROR: LoadError: UndefVarError: include not defined

I don’t understant this behaviour. On the other hand if I put the include statement inside module A, I get a

> LoadError: ArgumentError: Package aux not found in current path

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 13, 2021, 10:15am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084/2 "2021-09-13T10:15:52Z")

</div>

Put the `include` inside `module A`. Basically, for a package, there shouldn’t really be anything outside the `module` of the package.

Regarding the error on `using Aux`, that is not surprising since the `Aux` module is inside `A`. So you can do:

```julia
using A
using A.Aux

```

---

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [September 13, 2021, 11:37am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084/3 "2021-09-13T11:37:38Z")

</div>

Thanks kristoffer, it makes sense.  
Now, if I want to define and test two different modules A, B in the _same_ package, how do I do ? For instance, I would like something like

```julia
#src/A.jl
module A
export f
f(x)=x
end

module B
export g
g(x)=x+1
end

```

and

```julia
#test/runtests.jl
using Test
using A,B
@test f(0)==0
@test g(0)==1

```

I get a

> LoadError: ArgumentError: Package aux not found in current path:
> 
> - Run `import Pkg; Pkg.add("B")` to install the aux package.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 13, 2021, 11:52am UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084/4 "2021-09-13T11:52:06Z")

</div>

> [@sim](#):
>
> Now, if I want to define and test two different modules A, B in the _same_ package, how do I do ?

Your package is `A` here. And note:

> [@kristoffer.carlsson](#):
>
> Basically, for a package, there shouldn’t really be anything outside the `module` of the package.

You can define a module `B` inside `A` as:

```julia
module A

module B
end

end

```

You can only test a full package, you cannot test a submodule of a package. Then you would need to make B its own package.

---

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [September 13, 2021, 12:09pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084/5 "2021-09-13T12:09:51Z")

</div>

Thanks. So a single package, say A, can only define a single module of the same name A ?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 13, 2021, 12:11pm UTC](https://discourse.julialang.org/t/loaderror-undefvarerror-include-not-defined-when-using-pkg-test/68084/6 "2021-09-13T12:11:35Z")

</div>

Yes. Everything else has to be inside `A`.
