Write snippets of code in your documentation and execute them as regression tests.

View project on GitHub

Django Integration

Starting from byexample 9.0.1, we have integration with Django.

When you are developing an app in Django it is common to explore it using a Python shell with all the settings needed by Django already loaded.

You probably do:

$ python shell            # byexample: +skip

To run byexample inside the same environment having all the settings preloaded you just need a custom shebang

$ byexample -l python -x-shebang 'python:%p %a shell -i python' <your files> # byexample: +skip

That’s too much to type!

Remember that you can save part of the command line in a file:

$ cat - > test/ds/django.conf <<EOF
> -x-shebang=python:%p %a shell -i python

$ byexample -l python @test/ds/django.conf <your files>       # byexample: +skip

How it works?

-x-shebang 'python:%p %a shell -i python' tells byexample to use %p %a shell -i python as the interpreter to execute the examples written in Python.

%p %a shell -i python will run something similar to python shell except that some extra flags are needed to customize the interpreter (hidden behind the magic %a).

Check shebang for more details.

Other difference is that will use the more human friendly ipython interpreter.

Currently byexample has no support for it (pull requests are welcome!) so the extra flag -i python tells to use the classic python interpreter.