-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
20 lines (17 loc) · 726 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import pytest,os,re,io,sys,mock,json
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
@pytest.mark.it('Use the function print()')
def test_for_file_output(capsys):
with open(path, 'r') as content_file:
content = content_file.read()
pattern = (r"print\s*\(")
regex = re.compile(pattern)
assert bool(regex.search(content)) == True
@pytest.mark.it("We tried with age 50 and it was supposed to return 60")
@mock.patch('builtins.input', lambda x: 50)
def test_plus_ten(stdin):
# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
sys.stdout = buffer = io.StringIO()
import app
captured = buffer.getvalue()
assert captured == "Your age is: 60\n"