This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
forked from zak-hassan/internship-bootcamp-workshops
-
Notifications
You must be signed in to change notification settings - Fork 27
/
test_generic.py
47 lines (37 loc) · 1.54 KB
/
test_generic.py
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
#!/usr/bin/env python3
# Copyright(C) 2019 <your-name and e-mail>
#
# This program is free software: you can redistribute it and / or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Show a very generic usage of PyTest.
This module does not have any tested counter-part in the myproject module.
It just shows few use-cases on how to use PyTest.
"""
# Let's import pytest module for the pytest.raises() and parametrize used later:
import pytest
def test_not_equal():
"""Check that not-equal sign checks values correctly."""
assert 1 != 0, "Zero is not equal to one"
def test_raise_exception():
"""Check if there is raised an exception on error state."""
with pytest.raises(ValueError):
raise ValueError("Value was not provided correctly")
@pytest.mark.parametrize("a,b,expected", [
(0, 1, -1),
(1, 0, 1),
(1, .5, .5),
])
def test_sub(a, b, expected):
"""A simple test-case which shows how to parametrize tests."""
diff = a - b
assert diff == expected, "It looks like subtract does not work correctly!"