2010-10-11 05:45:45 +08:00
|
|
|
|
2010-10-13 18:26:14 +08:00
|
|
|
doctest integration for modules and test files.
|
2010-10-11 05:45:45 +08:00
|
|
|
=========================================================
|
|
|
|
|
|
|
|
By default all files matching the ``test*.txt`` pattern will
|
|
|
|
be run through the python standard ``doctest`` module. You
|
|
|
|
can change the pattern by issuing::
|
|
|
|
|
|
|
|
py.test --doctest-glob='*.rst'
|
|
|
|
|
|
|
|
on the command line. You can also trigger running of doctests
|
|
|
|
from docstrings in all python modules (including regular
|
|
|
|
python test modules)::
|
|
|
|
|
|
|
|
py.test --doctest-modules
|
|
|
|
|
|
|
|
You can make these changes permanent in your project by
|
|
|
|
putting them into a conftest.py file like this::
|
|
|
|
|
|
|
|
# content of conftest.py
|
|
|
|
option_doctestmodules = True
|
|
|
|
option_doctestglob = "*.rst"
|
|
|
|
|
2010-10-11 16:07:14 +08:00
|
|
|
If you then have a text file like this::
|
|
|
|
|
|
|
|
# content of example.rst
|
|
|
|
|
|
|
|
hello this is a doctest
|
|
|
|
>>> x = 3
|
|
|
|
>>> x
|
|
|
|
3
|
|
|
|
|
|
|
|
and another like this::
|
|
|
|
|
|
|
|
# content of mymodule.py
|
|
|
|
def something():
|
|
|
|
""" a doctest in a docstring
|
|
|
|
>>> something()
|
|
|
|
42
|
|
|
|
"""
|
|
|
|
return 42
|
|
|
|
|
|
|
|
then you can just invoke ``py.test`` without command line options::
|
|
|
|
|
|
|
|
$ py.test
|
2010-10-12 16:59:04 +08:00
|
|
|
=========================== test session starts ============================
|
2010-11-02 07:53:53 +08:00
|
|
|
platform linux2 -- Python 2.6.5 -- pytest-2.0.0.dev17
|
|
|
|
test path 1: /tmp/doc-exec-197
|
2010-10-11 16:07:14 +08:00
|
|
|
|
2010-11-02 07:53:53 +08:00
|
|
|
============================= in 0.00 seconds =============================
|