Have you seen Elixir's doctests[1]? They're docs with a code example that gets run by your tests, and if the example doesn't work, your tests fail.
[1]https://elixir-lang.org/getting-started/mix-otp/docs-tests-a...
[1]https://elixir-lang.org/getting-started/mix-otp/docs-tests-a...
Sphinx also has additional doc testing methods that let you test the code examples in your actual docs: http://www.sphinx-doc.org/en/stable/ext/doctest.html
Here's an example:
##Examples
iex> user = Repo.insert!(%MyApp.User{id: 1, some_state: "whatever"})
...> {:ok, user} = MyApp.Users.DataTransformer.transform_with_effects(user)
...> Repo.one(where: MyApp.User.id == 1).some_state
"new state"