Pkg.project() inside a unit test

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.

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.

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.