pytest material
This commit is contained in:
@@ -6,6 +6,7 @@ name = "pypi"
|
||||
[packages]
|
||||
|
||||
[dev-packages]
|
||||
pytest = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.8"
|
||||
|
68
intro_pytest/Pipfile.lock
generated
68
intro_pytest/Pipfile.lock
generated
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "7f7606f08e0544d8d012ef4d097dabdd6df6843a28793eb6551245d4b2db4242"
|
||||
"sha256": "44ccf4c66d663506b934edaa5a4873daba29d125557d68c7840956adb918c913"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@@ -16,5 +16,69 @@
|
||||
]
|
||||
},
|
||||
"default": {},
|
||||
"develop": {}
|
||||
"develop": {
|
||||
"attrs": {
|
||||
"hashes": [
|
||||
"sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1",
|
||||
"sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
|
||||
"version": "==21.2.0"
|
||||
},
|
||||
"iniconfig": {
|
||||
"hashes": [
|
||||
"sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3",
|
||||
"sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"
|
||||
],
|
||||
"version": "==1.1.1"
|
||||
},
|
||||
"packaging": {
|
||||
"hashes": [
|
||||
"sha256:7dc96269f53a4ccec5c0670940a4281106dd0bb343f47b7471f779df49c2fbe7",
|
||||
"sha256:c86254f9220d55e31cc94d69bade760f0847da8000def4dfe1c6b872fd14ff14"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==21.0"
|
||||
},
|
||||
"pluggy": {
|
||||
"hashes": [
|
||||
"sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159",
|
||||
"sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==1.0.0"
|
||||
},
|
||||
"py": {
|
||||
"hashes": [
|
||||
"sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3",
|
||||
"sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==1.10.0"
|
||||
},
|
||||
"pyparsing": {
|
||||
"hashes": [
|
||||
"sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1",
|
||||
"sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"
|
||||
],
|
||||
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==2.4.7"
|
||||
},
|
||||
"pytest": {
|
||||
"hashes": [
|
||||
"sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89",
|
||||
"sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==6.2.5"
|
||||
},
|
||||
"toml": {
|
||||
"hashes": [
|
||||
"sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
|
||||
"sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
|
||||
],
|
||||
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
|
||||
"version": "==0.10.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
22
intro_pytest/function.py
Normal file
22
intro_pytest/function.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# function.py
|
||||
|
||||
|
||||
class Maths:
|
||||
"""
|
||||
A Maths class
|
||||
n (int) - starting interger value
|
||||
"""
|
||||
|
||||
def __init__(self, n: int):
|
||||
self.n = n
|
||||
|
||||
def add(self, x: int) -> int:
|
||||
self.n += x
|
||||
return self.n
|
||||
|
||||
def subtract(self, x: int) -> int:
|
||||
self.n -= x
|
||||
return self.n
|
||||
|
||||
def __repr__(self):
|
||||
return f"n is {self.n}"
|
0
intro_pytest/tests/__init__.py
Normal file
0
intro_pytest/tests/__init__.py
Normal file
30
intro_pytest/tests/test_function.py
Normal file
30
intro_pytest/tests/test_function.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# test_function.py
|
||||
import pytest
|
||||
|
||||
from function import Maths
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def maths():
|
||||
return Maths(10)
|
||||
|
||||
|
||||
def test_exists(maths):
|
||||
"""
|
||||
Checks if objects are created
|
||||
"""
|
||||
assert isinstance(maths, Maths)
|
||||
|
||||
|
||||
def test_add(maths):
|
||||
"""
|
||||
Addition method
|
||||
"""
|
||||
assert maths.add(10) == 20
|
||||
|
||||
|
||||
def test_subtract(maths):
|
||||
"""
|
||||
Subtraction method
|
||||
"""
|
||||
assert maths.subtract(5) == 5
|
Reference in New Issue
Block a user