# Setting up tests: problems with \`using myModule\`

**URL:** <https://discourse.julialang.org/t/setting-up-tests-problems-with-using-mymodule/18495>\
**Category:** General Usage\
**Tags:** testing, module\
**Created:** [December 9, 2018, 4:27pm UTC](https://discourse.julialang.org/t/setting-up-tests-problems-with-using-mymodule/18495 "2018-12-09T16:27:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![natemcintosh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/natemcintosh/32/9021_2.png) [@natemcintosh](https://discourse.julialang.org/u/natemcintosh)\
**Post date:** [December 9, 2018, 4:27pm UTC](https://discourse.julialang.org/t/setting-up-tests-problems-with-using-mymodule/18495/1 "2018-12-09T16:27:10Z")

</div>

I’m attempting to create my own module (for the purpose of educating myself) and write tests for it. However, when attempting to call `using myOpti` in my test, I keep running into the error

`ERROR: LoadError: ArgumentError: Package myOpti not found in current path: Run import Pkg; Pkg.add("myOpti") to install the myOpti package.`

In the directory `Users/natemcintosh/Documents/Julia/basicOptimization` I have set up a git repository. Within the repository is a `src` directory and a `test` directory.

In `src` are two files: `myOpti.jl` and `problem_set_1a.jl`.

`problem_set_1a.jl` is where I keep the functions I want to be in the module.

`myOpti.jl` contains only the code   
`module myOpti include("problem_set_1a.jl") end # module ps1a`

At the moment, `problem_set_1a.jl` does not export anything. Is this something I need to do?

I’ve also added the path to the `LOAD_PATH` so that `Users/natemcintosh/Documents/Julia/basicOptimization` now appears at the end of the `LOAD_PATH`.

Any suggestions to get this to work?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 9, 2018, 5:48pm UTC](https://discourse.julialang.org/t/setting-up-tests-problems-with-using-mymodule/18495/2 "2018-12-09T17:48:52Z")

</div>

Probably the easiest thing to do is:

1. Reorganize your files a little bit so that the file defining your module lives in `...basicOptimization/myOpti/src/myOpti.jl`
2. Undo any modifications to your `LOAD_PATH` (it’s no longer needed since Julia 1.0)
3. Start Julia, press `]` to get the `pkg>` prompt, and then do:

```julia
pkg> dev /Users/natemcintosh/Documents/Julia/basicOptimization/myOpti

```

---

<div class="post-metadata">

**Author:** ![natemcintosh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/natemcintosh/32/9021_2.png) [@natemcintosh](https://discourse.julialang.org/u/natemcintosh)\
**Post date:** [December 9, 2018, 6:51pm UTC](https://discourse.julialang.org/t/setting-up-tests-problems-with-using-mymodule/18495/3 "2018-12-09T18:51:14Z")

</div>

Horay! It now finds the module and begins to compile! Thank you so much for the help!

Now I have a new error, but I suppose that’s the definition of progress; moving from one error to the next.

[Info: Precompiling myOpti [ce8f6948-e2c0-503c-b155-f6049321a3fd]  
┌ Warning: Package myOpti does not have CSVFiles in its dependencies:  
│ - If you have myOpti checked out for development and have  
│ added CSVFiles as a dependency but haven’t updated your primary  
│ environment’s manifest file, try `Pkg.resolve()`.  
│ - Otherwise you may need to report an issue with myOpti  
└ Loading CSVFiles into myOpti from project dependency, future warnings for myOpti are suppressed.  
WARNING: using myOpti.myOpti in module Main conflicts with an existing identifier.  
ERROR: LoadError: importing myOpti into Main conflicts with an existing identifier  
in expression starting at /Users/natemcintosh/Documents/Julia/basicOptimization/myOpti/test/test\_ps1.jl:3

I suppose now I have to add dependencies? Is this something I do with a `REQUIRE` file?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 9, 2018, 8:28pm UTC](https://discourse.julialang.org/t/setting-up-tests-problems-with-using-mymodule/18495/4 "2018-12-09T20:28:48Z")

</div>

The error is just because you probably already had a module defined with the same name in your existing Julia session. Restarting Julia should fix it.

Adding dependencies via a REQUIRE file will still work, but that’s the old way of doing things and will eventually be deprecated. The new approach is via [Pkg · The Julia Language](https://docs.julialang.org/en/v1.0/stdlib/Pkg/#Creating-your-own-packages-1)

For example, to declare that myOpti depends on CSVFiles, you could do:

```julia
<start a new julia session>
pkg> activate <whatever/basicOptimization/myOpti 
pkg> add CSVFiles

```

Note that you might find it easier to let Julia generate the basic package structure for you to avoid having to figure out some of these things in the future. That’s as easy as:

```julia
pkg> generate MyOptiPackage

```

which will create a `Project.toml` file and a module source file for you, with the right folder structure already.
