File: doctest.txt

package info (click to toggle)
pytest 2.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,564 kB
  • sloc: python: 16,243; makefile: 162; sh: 68
file content (53 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

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
putting them into a pytest.ini file like this::

    # 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
        >>> something()
        42
        """
        return 42

then you can just invoke ``py.test`` without command line options::

    $ py.test
    =========================== test session starts ============================
    platform darwin -- Python 2.7.1 -- pytest-2.2.2
    collecting ... collected 1 items
    
    mymodule.py .
    
    ========================= 1 passed in 0.51 seconds =========================
    [?1034h