|
2 | 2 | path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
|
3 | 3 |
|
4 | 4 |
|
5 |
| -@pytest.mark.it('Variable "age" should exist') |
6 |
| -def test_for_file_output(capsys, app): |
7 |
| - result = app.age |
8 |
| - assert result == True |
| 5 | +@pytest.mark.it('The variable age should exist') |
| 6 | +def test_variable_exists(capsys): |
| 7 | + import app |
| 8 | + try: |
| 9 | + app.age |
| 10 | + except AttributeError: |
| 11 | + raise AttributeError("The variable age should exist") |
| 12 | + |
9 | 13 |
|
10 | 14 |
|
11 | 15 | @pytest.mark.it('Use the function print()')
|
12 | 16 | def test_for_file_output(capsys):
|
13 |
| - |
14 | 17 | with open(path, 'r') as content_file:
|
15 | 18 | content = content_file.read()
|
16 |
| - pattern = r"print\s*\(" |
| 19 | + pattern = (r"print\s*\(") |
17 | 20 | regex = re.compile(pattern)
|
18 | 21 | assert bool(regex.search(content)) == True
|
19 | 22 |
|
| 23 | + |
20 | 24 | @pytest.mark.it("We tried with age 50 and it was supposed to return 60")
|
21 | 25 | @mock.patch('builtins.input', lambda x: 50)
|
22 | 26 | def test_plus_ten(stdin):
|
23 |
| - # f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') |
24 |
| - sys.stdout = buffer = io.StringIO() |
25 |
| - import app |
26 |
| - captured = buffer.getvalue() |
27 |
| - assert captured == "Your age is: 60\n" |
| 27 | + # f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') |
| 28 | + sys.stdout = buffer = io.StringIO() |
| 29 | + import app |
| 30 | + captured = buffer.getvalue() |
| 31 | + assert captured == "Your age is: 60\n" |
0 commit comments