TestEnv.jl icon indicating copy to clipboard operation
TestEnv.jl copied to clipboard

How to check whether we are already in an testenv?

Open schlichtanders opened this issue 3 years ago • 4 comments

The test_env path is very cryptic. It would be great, if it could include testenv or some other explicit name, which makes it easy to check, whether we have already loaded the test environment.

Usecase: Get idempotent execution

import TestEnv
if "testenv" ∉ Base.active_project()
  TestEnv.activate()
end

schlichtanders avatar Nov 06 '22 21:11 schlichtanders

my current workaround is try and catch

try import TestEnv; TestEnv.activate(); catch; end

schlichtanders avatar Nov 06 '22 22:11 schlichtanders

I think that would be a good idea, to include it in the path. I think that change would be faily easy. Just change where we mktempdir to mkdir(joinpath(mktempdir, testenv))

oxinabox avatar Nov 07 '22 16:11 oxinabox

Perhaps it would be better to have a function TestEnv.in_test_env()::Bool that would return true either:

  • if TestEnv.activate() has been called before
  • or if within a Pkg.test() execution

and false otherwise?

nrontsis avatar Feb 13 '23 10:02 nrontsis

Yes.

oxinabox avatar Mar 08 '23 05:03 oxinabox