forked from rasbt/python_reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoctest_example.py
More file actions
47 lines (39 loc) · 961 Bytes
/
doctest_example.py
File metadata and controls
47 lines (39 loc) · 961 Bytes
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
# doctest example
# Sebastian Raschka 11/19/2013
def subtract(a, b):
"""
Subtracts second from first number and returns result.
>>> subtract(10, 5)
5
>>> subtract(11, 0.7)
10.3
"""
return a-b
def hello_world():
"""
Returns 'Hello, World'
>>> hello_world()
"Hello, World"
>>> hello_world()
'Hello, World'
"""
return "Hello, World"
if __name__ == "__main__": # is 'false' if imported
import doctest
doctest.testmod()
""" RESULTS
sebastian ~/Desktop> python3 doctest_example.py
**********************************************************************
File "doctest_example.py", line 17, in __main__.hello_world
Failed example:
hello_world()
Expected:
"Hello, World"
Got:
'Hello, World'
**********************************************************************
1 items had failures:
1 of 2 in __main__.hello_world
***Test Failed*** 1 failures.
sebastian ~/Desktop>
"""