To pry or not to pry

When I am not touching front-end code, I pretty much live in the testing environment when doing development. I almost never drop into to dev at all. I find that since dev requires setting up state, why not just have a test case ready that has it and drop in using pry?

So, the start of my debugging often begins with:

iex -S mix test --trace /path/to/test:100

Or, since someone introduced me to dbg it’s turned into:

iex --dbg pry -S mix test --trace /path/to/test:100

I’m in the process of refining some little QoL things and one of the kinda annoying things in this flow is that an iex shell opens even in the absence of IEx.pry() or dbg(). It’s not the worst thing in world as a quick ctrl + c x2 gets me out of there. Still, is there a way to use the same command to only pop the iex session if I include some kind of pry?

The nice thing about this is that I always just use one command to figure off my single tests.

Is there a way to accomplish this?


Sorry I don’t have an answer but this is cool, thanks for giving me some stuff to look into! I wasn’t aware of --dbg pry.

lol. I liiterally learned about dbg today from a co-worker. My first thought was, “Okay, how long have I been a caveman?”

The answer, as it turns out, is about one year and four months since Elixir 1.14 was released.

My second thought was, “Why haven’t I made a terminal alias for this yet?” That’s since been rectified.

The excellent improvements to all things error-related in 1.16 have had me thinking more and more about QoL as of late.

I remember when dbg first was introduced it pry’d by default but people didn’t like that. I just got used to it not doing it anymore once it was taken away, but obviously makes sense you still have the option, lol.

In these discussions I always mix up Erlang dbg, :dbg, and Elixir dbg. :laughing:

So… completely by accident, I noticed something changed with tests—I’m guessing in 1.16, although it might have been 1.15. This happened while messing with terminal aliases.

At some point, definitely in 1.14, in order to get IEX.pry to work in a tests I’d have to do this:

iex -S mix test /path/to/test.exs

That is no longer required.


mix test /path/to/test.exs

Will open up an iex terminal with pry if IEX.pry() is in the code. Otherwise, it will ignore it and not just open an iex terminal at the end. This was the functionality I was looking for in this post anyway.