# Pkg.project() inside a unit test

**URL:** <https://discourse.julialang.org/t/pkg-project-inside-a-unit-test/87337>\
**Category:** General Usage\
**Created:** [September 15, 2022, 8:43pm UTC](https://discourse.julialang.org/t/pkg-project-inside-a-unit-test/87337 "2022-09-15T20:43:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rssdev10](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@rssdev10](https://discourse.julialang.org/u/rssdev10)\
**Post date:** [September 15, 2022, 8:43pm UTC](https://discourse.julialang.org/t/pkg-project-inside-a-unit-test/87337/1 "2022-09-15T20:43:25Z")

</div>

Is any way to get the current package name while running a unit test? The issue `Pkg.project().name` gives `nothing` I’m activating the tests with `]test`

The reason why I need it, I want to have a template unit test that might be added to multiple packages and activate a function inside. But for that, I need to have an access to the module inside the package. The code below works anywhere outside a unit test.

```julia
using Pkg

pkg = Pkg.project().name
@eval using $(Symbol(pkg))
m = getfield(Main, Symbol(pkg))
....
m.AppServer.start_server(...)

```

If I’m replacing `Pkg.project().name` in the sample above by an actual name, everything is working fine, but I cannot reuse that file in different projects without changes.

---

<div class="post-metadata">

**Author:** ![Graham\_Gill](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/graham_gill/32/9269_2.png) [@Graham\_Gill](https://discourse.julialang.org/u/Graham_Gill)\
**Post date:** [July 23, 2024, 2:37am UTC](https://discourse.julialang.org/t/pkg-project-inside-a-unit-test/87337/2 "2024-07-23T02:37:50Z")

</div>

I realise your post was 22 months ago, but I just came across it.

`Pkg.project().name` and `Pkg.project().version` evaluate to `nothing` when `Pkg.project().uuid == nothing`.

In other words, you need to have a `uuid` entry in `Project.toml` in order for `Pkg.project()` to report whatever `name` and `version` entries are in the project file.

I don’t know why that’s the case. I know that without a `uuid` field it’s not a full-fledged package, but `Project.toml` is used by non-package projects too and it would be helpful if the `name` and `version` set in `Project.toml` were reported whether or not the project is defining a proper package.
