Doctests in Livebook not working

Hi everybody! :slight_smile:

When trying to use doctests in Livebook, I get this error:

** (ExUnit.DocTest.Error) #cell:brdghoceywtzil2oxanrzvpyqvy6mdh5: could not retrieve the documentation for module Foo. The BEAM file of the module cannot be accessed
    (ex_unit 1.14.0) lib/ex_unit/doc_test.ex:513: ExUnit.DocTest.extract/1
    (ex_unit 1.14.0) lib/ex_unit/doc_test.ex:235: ExUnit.DocTest.__doctests__/2
    #cell:ex3gg7bj43xze5ovqwpk3rmwtdj3y533:5: (module)
    (elixir 1.14.0) src/elixir_compiler.erl:65: :elixir_compiler.dispatch/4
    (elixir 1.14.0) src/elixir_compiler.erl:50: :elixir_compiler.compile/3
    (elixir 1.14.0) src/elixir_module.erl:379: :elixir_module.eval_form/6
    (elixir 1.14.0) src/elixir_module.erl:105: :elixir_module.compile/5
    (elixir 1.14.0) src/elixir_lexical.erl:15: :elixir_lexical.run/3
    #cell:ex3gg7bj43xze5ovqwpk3rmwtdj3y533:3: (file)

Does anybody have an idea what is wrong? Or is this even supposed to work? It would be really cool if yes. :pinched_fingers:

Example Livebook code:

defmodule Foo do
  @doc """
      iex> Foo.bar()
      "X"
  """
  def bar, do: "X"
end

ExUnit.start(auto_run: false)

defmodule FooTest do
  use ExUnit.Case, async: false
  doctest Foo
end

ExUnit.run()
1 Like

This is a known issue and is already fixed in Livebook’s main branch, but it hasn’t made it into a release yet.

I recently filed this issue and found all this out. :slight_smile:

3 Likes

FYI, it’s released now in the version 0.8.0.

1 Like