julia-vscode / TestItemRunner.jl

Run Julia test items
MIT License
76 stars 11 forks source link

What is the environment used by the test code when running a @testitem ? #29

Closed reumle closed 1 year ago

reumle commented 1 year ago

[first time user] Hi! I am trying to run one @testitem , which tests the output of a startup file for my package. This startup file runs in a specific environment. But the @testitem runs in another environment ("AE") and I am stuck when trying to upgrade it with the packages I need to actually run the test: Eg, from within the testitem, I can not even add Pkg...

When trying , this line fails :

 import Pkg

With this error message:

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

So it looks like i need to know which environment the testitem runs in, and manually add Pkg there....

Thank you!

Whole file below.


#1. This runs: the "launcher" for the "main" function.

rootPath="C:\\proj\\Rprojs\\PS1908\\julia\\21T4_vormdp"

data_dir = rootPath * "\\datafiles\\"
packagePath = rootPath * "\\ValueOrientedRiskManagementInsurance.jl"
cd(packagePath * "\\mains")
using Pkg
Pkg.activate(".")
using Revise
using XLSX,PrettyTables,Eyeball,TestItems,TestItemRunner
using DataFrames, LinearAlgebra, ValueOrientedRiskManagementInsurance,CSV
const vorm = ValueOrientedRiskManagementInsurance     # <- the package I am working on.
is_print=Dict(:is_print => true)

include(".\\vormi_22_07_09_base.jl") # the actual source file, containing the `main` function.
zzz=main(5;is_print=is_print);

#2.  This fails, on running the testitem.

@testitem "structure only" begin
  rootPath="C:\\proj\\Rprojs\\PS1908\\julia\\21T4_vormdp"
  data_dir = rootPath * "\\datafiles\\"
  packagePath = rootPath * "\\ValueOrientedRiskManagementInsurance.jl"
  cd(packagePath * "\\mains")
  import Pkg                # <- offending line on running test item, erreor message above.
  Pkg.add("Pkg")
  Pkg.activate(".")
  using XLSX,PrettyTables,Eyeball,TestItems,TestItemRunner
  using DataFrames, LinearAlgebra, ValueOrientedRiskManagementInsurance,CSV
  const vorm = ValueOrientedRiskManagementInsurance

  include(".\\vormi_22_07_09_base.jl")

  is_print=Dict(:is_print => true)
  zzz=main(5;is_print=is_print);
  @test propertynames(zzz) == (:Projection, :product, :invs, :liab_ins, :liab_other)  
end
davidanthoff commented 1 year ago

They use the same test env structure as the base test system. So the easiest way to make some packages available during testing is to add them to the standard test target in the package Project.toml.