-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest_repl.py
More file actions
56 lines (46 loc) · 1.15 KB
/
test_repl.py
File metadata and controls
56 lines (46 loc) · 1.15 KB
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
import pathlib
from pytest import skip
import pytest_codeblocks
def test_repr(testdir):
string1 = """
```python
>>> print("Hello World!")
Hello World!
```
"""
testdir.makefile(".md", string1)
result = testdir.runpytest("--codeblocks")
result.assert_outcomes(passed=1)
def test_cont(testdir):
string1 = """
```python
>>> def add(a, b):
... return a + b
```
<!--pytest-codeblocks:cont-->
```python
>>> add(2,7)
9
```
"""
testdir.makefile(".md", string1)
result = testdir.runpytest("--codeblocks")
result.assert_outcomes(passed=1)
def test_exception(testdir):
string1 = """
Handle the exception by doctest:
```python
>>> raise Exception("This should fail")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: This should fail
```
Handle the exception by pytest:
<!--pytest-codeblocks:expect-exception-->
```python
>>> raise Exception("This should fail")
```
"""
testdir.makefile(".md", string1)
result = testdir.runpytest("--codeblocks")
result.assert_outcomes(passed=2)