elixir - iex.iexs 文件未在测试环境中加载

标签 elixir elixir-mix elixir-iex

我正在尝试在调试测试时加载 iex.iexs 文件。我在 Mix.exs 中创建了一个别名来尝试导入它。

defp aliases do
    [
      ...,
      "ex.file": [&import_iex_file/1, "compile"]
    ]
  end

  defp import_iex_file(_var) do
    require IEx.Helpers
    # This raises a File.Error if ~/.iex.exs doesn't exist.
    if "./.iex.exs" |> Path.expand() |> File.exists?() do
      IEx.Helpers.import_file("./.iex.exs")
    end
  end

当我使用 iex -S mix test_path 运行测试时,文件已加载,但是当它停止在 IEx.pry 时,我无法访问该别名我在 .iex.iex 文件中添加了。

最佳答案

请注意,文件名应为 .iex.exs。正如您所注意到的,运行测试不会启动 IEx session ,因此不会加载该文件。相反,最好在 tests/test_helper.exs 文件中进行测试所需的任何设置。如果您确实需要重复使用 .iex.exs 文件中的设置/快捷方式,您可以将其包含在 test_helper.exs 文件中,如下所示:

# tests/test_helper.exs
require IEx.Helpers
IEx.Helpers.import_file(".iex.exs")
ExUnit.start()

关于elixir - iex.iexs 文件未在测试环境中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71485272/

相关文章:

elixir - Phoenix 应用程序启动通话功能

elixir - 为什么 MIX 依赖在依赖的语义版本之前有一个 "~>"?

elixir - 自定义混合任务未加载测试环境

elixir - 在 Elixir 单元测试中导入测试代码

c - Elixir NIF 中正确的资源处理

oauth-2.0 - Google Calendar API 在 OAuth 期间出现 403 错误,即使它似乎授予访问权限

compiler-errors - 如何在不编译更改文件的情况下运行 `iex -S mix`?

elixir - 如何为 Elixir iex 提示着色?

math - 在 Elixir 中使 float 变圆的最佳方法是什么

elixir - Ecto assoc_constraint 不起作用