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

发布于 2025-01-14 20:00:59 字数 594 浏览 1 评论 0原文

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

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 文件。

I'am trying to load the iex.iexs file when debugging a test. I created an alias in Mix.exs that tries to import it.

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

When I run a test with iex -S mix test_path the file is loaded, but when it stop at the IEx.pry I can't access the aliases that I added at the .iex.iex file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲鸠 2025-01-21 20:00:59

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

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

Note the file name should be .iex.exs. As you have noticed, running tests does not start an IEx session, so the file is not loaded. Instead, it might be better to do whatever setups you need for tests inside your tests/test_helper.exs file. If you really need to re-use the settings/shortcuts in your .iex.exs file, you can include it from your test_helper.exs file something like this:

# tests/test_helper.exs
require IEx.Helpers
IEx.Helpers.import_file(".iex.exs")
ExUnit.start()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文