Hi, Im have some tests which delete the tempdir()
folder before exiting. They works perfectly. But, the problem is that if I call the tests again in the same process (e.g. using a REPL) the tests engine (Pkg
) fails. Is this intended? Is deleting tempdir()
a terrible practice? I must remark that Pkg
fails regarded tempdir()
is used in the tests or not.
Here a MWE:
using Pkg
# utils
printerr(err) = print(sprint(showerror, err, catch_backtrace()))
# creating package
pkg_name = "TestIssuePkg"
println("\n\n\n")
@info "Creating test pkg" pkg_name
println("\n\n")
pkg_path = joinpath(Pkg.devdir(), pkg_name)
rm(pkg_path; force = true, recursive = true)
Pkg.generate(pkg_path)
# adding Test extras
proj_file = joinpath(pkg_path, "Project.toml")
open(proj_file, "a") do io
println(io,
"""
[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[targets]
test = ["Test"]
"""
)
end
# adding runtests
# Note that the tests are empty
test_dir = joinpath(pkg_path, "test")
mkpath(test_dir)
write(joinpath(test_dir, "runtests.jl"),
"""
using $(pkg_name)
using Test
@testset "$(pkg_name).jl" begin
@test true
end
"""
)
# running tests
Pkg.activate(pkg_path)
println("\n\n\n")
@info "This should pass"
println("\n\n")
mkpath(tempdir())
Pkg.test()
println("\n\n\n")
@info "Pkg.test() fails if 'isdir(tempdir()) == false'"
println("\n\n")
rm(tempdir(); force = true, recursive = true)
try
Pkg.test()
catch err
printerr(err)
end
println("\n\n\n")
@info "If I run mkpath(tempdir()) autside 'test' it works again"
println("\n\n")
mkpath(tempdir())
Pkg.test()
Thanks