test_ok1/doc/en/doctest.txt

59 lines
1.4 KiB
Plaintext
Raw Normal View History

Doctest integration for modules and test files
=========================================================
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
2010-11-26 20:26:56 +08:00
putting them into a pytest.ini file like this::
2010-11-26 20:26:56 +08:00
# content of pytest.ini
[pytest]
addopts = --doctest-modules
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
2010-11-26 20:26:56 +08:00
>>> something()
42
"""
return 42
then you can just invoke ``py.test`` without command line options::
$ py.test
=========================== test session starts ============================
2013-10-04 01:09:18 +08:00
platform linux2 -- Python 2.7.3 -- pytest-2.4.2
collected 1 items
2010-11-26 20:26:56 +08:00
mymodule.py .
2013-10-04 01:09:18 +08:00
========================= 1 passed in 0.01 seconds =========================
It is possible to use fixtures using the ``getfixture`` helper::
# content of example.rst
>>> tmp = getfixture('tmpdir')
>>> ...