File: doctests.py

package info (click to toggle)
pytest-doctestplus 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 352 kB
  • sloc: python: 1,978; makefile: 13; sh: 7
file content (116 lines) | stat: -rw-r--r-- 2,279 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Licensed under a 3-clause BSD style license - see LICENSE.rst

"""
Also module level skips should be matched with `*` and `.`, test at least
the `.` version (the star would match all others too).

>>> import foobar
"""

__doctest_skip__ = [
    'skip_this_test',
    'ClassWithSomeBadDocTests.this_test_fails',
    'ClassWithAllBadDocTests.*',
]

__doctest_requires__ = {
    '.': ['foobar'],
    'depends_on_foobar': ['foobar'],
    'depends_on_foobar_submodule': ['foobar.baz'],
    'depends_on_two_modules': ['os', 'foobar'],
}


def this_test_works():
    """
    This test should be executed by --doctest-plus and should pass.

    >>> 1 + 1
    2
    """


def skip_this_test():
    """
    This test will cause a failure if __doctest_skip__ is not working properly.

    >>> x + y
    2
    """


def depends_on_real_module():
    """
    This test should be executed by --doctest-plus and should pass.

    >>> import os
    >>> os.path.curdir
    '.'
    """


def depends_on_foobar():
    """
    This test will cause a failure if __doctest_requires__ is not working.

    >>> import foobar
    >>> foobar.foo.bar('baz')
    42
    """


def depends_on_foobar_submodule():
    """
    This test will cause a failure if __doctest_requires__ is not working.

    >>> import foobar.baz
    >>> foobar.baz.bar('baz')
    42
    """


def depends_on_two_modules():
    """
    This test will cause a failure if __doctest_requires__ is not working.

    >>> import os
    >>> import foobar
    >>> foobar.foo.bar(os.path.curdir)
    'The meaning of life'
    """


class ClassWithSomeBadDocTests:
    def this_test_works():
        """
        This test should be executed by --doctest-plus and should pass.

        >>> 1 + 1
        2
        """

    def this_test_fails():
        """
        This test will cause a failure if __doctest_skip__ is not working.

        >>> x + y
        5
        """


class ClassWithAllBadDocTests:
    def this_test_fails(self):
        """
        This test will cause a failure if __doctest_skip__ is not working.

        >>> x + y
        5
        """

    def this_test_also_fails(self):
        """
        This test will cause a failure if __doctest_skip__ is not working.

        >>> print(blue)
        'blue'
        """