...
Code Block | ||
---|---|---|
| ||
pytest pytest -k zero -v |
Test passed. As expected, the division method returns a ZeroDivisionError exception.
...
We expect there is no possibility to select the 10th element from the list of three. Our test passed because of the IndexError exception.
TypeError example
...
Code Block | ||
---|---|---|
| ||
from sources.operations import select_item_from_list def test_select_item_from_list(): with pytest.raises(IndexError): select_item_from_list([1, 2, 3], 10) with pytest.raises(TypeError): select_item_from_list('list A', 'index') |
ValueError example
...
As expected there is no change to find a position of element '1' in an empty list. Let's run the test and check the output.
The ValueError raised and test_find_item_position_in_list test passed.
...
We used np. ndarray. all() to check if two NumPy arrays are equivalent.
The first test passed and raised a ValueError exception because there is no possibility to reshape the 4 elements list into 2x3 array. The second test also passed - a list of 4 elements can be reshaped into 2x2 array.
...