iex.iexs 文件未在测试环境中加载
我试图在调试测试时加载 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,文件名应为
.iex.exs
。正如您所注意到的,运行测试不会启动IEx
会话,因此不会加载该文件。相反,最好在tests/test_helper.exs
文件中进行测试所需的任何设置。如果您确实需要重复使用.iex.exs
文件中的设置/快捷方式,您可以将其包含在test_helper.exs
文件中,如下所示:Note the file name should be
.iex.exs
. As you have noticed, running tests does not start anIEx
session, so the file is not loaded. Instead, it might be better to do whatever setups you need for tests inside yourtests/test_helper.exs
file. If you really need to re-use the settings/shortcuts in your.iex.exs
file, you can include it from yourtest_helper.exs
file something like this: