Tests
Tests module.
python_package_template_test
This file contains examples of how to write tests using pytest!
Some good practices for writting great Python tests:
Source: https://www.nerdwallet.com/blog/engineering/5-pytest-best-practices/
- Prefer mocker over mock
- Parametrize the same behavior, have different tests for different behaviors
- Don’t modify fixture values in other fixtures
- Prefer responses over mocking outbound HTTP requests
- Prefer tmpdir over global test artifacts
TestGroup
A class with common parameters, param1
and param2
.
Source code in tests/python_package_template_test.py
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 |
|
fixt
fixt()
This fixture will only be available within the scope of TestGroup.
Returns:
-
int
(int
) –A common value to be used by multiple tests
Source code in tests/python_package_template_test.py
32 33 34 35 36 37 38 39 40 |
|
test_one
test_one(param1, param2, fixt)
Run the first test using the fixture.
Parameters:
-
param1
(str
) –First parameter.
-
param2
(str
) –Second parameter.
-
fixt
(int
) –Value from fixture.
Source code in tests/python_package_template_test.py
42 43 44 45 46 47 48 49 50 51 |
|
test_divide_error
test_divide_error(a, b, expected)
Check if divide returns correct Exceptions for known entries.
Issue raised by https://github.com/nullhack/python-project-template/issues/1337
Parameters:
-
a
(float
) –Dividend.
-
b
(float
) –Divisor.
-
expected
(Exception
) –expected Exception.
Source code in tests/python_package_template_test.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
test_divide_ok
test_divide_ok(a, b, expected)
Check if divide works for expected entries.
Parameters:
-
a
(float
) –Dividend.
-
b
(float
) –Divisor.
-
expected
(float
) –expected result.
Source code in tests/python_package_template_test.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|