Answer a question

Say I develop a package with a limited set of dependencies (for example, LinearAlgebra). In the Unit testing part, I might need additional dependencies (for instance, CSV to load a file). I can configure that in the Project.toml all good.

Now from there and in VS Code, how can I debug the Unit tests? I tried running the "runtests.jl" in the debugger; however, it unsurprisingly complains that the CSV package is unavailable.

I could add the CSV package (as a temporary solution), but I would prefer that the debugger run with the configuration for the unit testing; how can I achieve that?

As requested, here is how it can be reproduced (it is not quite minimal, but instead I used a commonly used package as it give confidence the package is not the problem). We will use DataFrames and try to execute the debugger for its unit tests.

  • Make a local version of DataFrames for the purpose of developing a feature in it. I execute dev DataFrames in a new REPL.
  • Select the correct environment (in .julia/dev/DataFrames) through the VS-code user interface.
  • Execute the "proper" unit testing by executing test DataFrames at the pkg prompt. Everything should go smoothly.
  • Try to execute the tests directly (open the runtests.jl and use the "Run" button in vs-code). I see some errors of the type:
LoadError: ArgumentError: Package CategoricalArrays not found in current path:
- Run `import Pkg; Pkg.add("CategoricalArrays")` to install the CategoricalArrays package.

which is consistent with CategoricalArrays being present in the [extras] section of the Project.toml but not present in the [deps].

  • Finally, instead of the "Run" command, execute the "Run and Debug". I encounter similar errors here is the first one:
Test Summary: | Pass  Total
merge         |   19     19
        PASSED: index.jl
        FAILED: dataframe.jl
LoadError: ArgumentError: Package DataStructures not found in current path:
- Run `import Pkg; Pkg.add("DataStructures")` to install the DataStructures package.

So I can't debug the code after the part requiring the extras packages.

  • After all that I delete this package with the command free DataFrames at the pkg prompt.

I see the same behavior in my package.

Answers

I'm not certain I understand your question, but I think you might be looking for the TestEnv package. It allows you to activate a temporary environment containing the [extras] dependencies. The discourse announcement contains a good description of the use cases.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐