Before the Lab
Read
Practical Python on Testing (mainly the part on
pytest
, at the end).
~/cs2613/labs/L15
In a terminal run
pipx install --include-deps unb-cs2613
listex.py
in the directory
you created above.symbols = 'HPQ,AAPL,IBM,MSFT,YHOO,DOA,GOOG'
symlist = symbols.split(',')
def test_lookup0():
assert symlist[0] == 'HPQ'
def test_lookup1():
assert symlist[1] == 'AAPL'
In ~/cs2613/labs/L15
, run
pytest listex.py
You should see
[student@id414m22 L15]$ pytest listex.py
=================== test session starts ===================
platform linux -- Python 3.9.16, pytest-7.4.3, pluggy-1.3.0
rootdir: /home1/ugrad/student/cs2613/labs/L15
plugins: pylama-8.4.1, cov-4.1.0
collected 2 items
listex.py .. [100%]
==================== 2 passed in 0.02s ====================
Modify one of the tests so it fails. Run pytest again.
Question for your journal: what are three ways failing tests are indicated?
For each of the remaining interactive evaluations in Exercise
1.19,
add a corresponding test to listex.py
.
make sure each test_*
function (def
) has a unique name.
if you want, you can have multiple asserts in a single test.
Questions for your journal:
==
in JavaScript and Python?node
test framework and pytest
Note that 1.26 shows you most of the pieces you need for 1.27
Add the following test to your solution for 1.27
def test_sum():
from pytest import approx
assert sum==approx(44671.15,abs=.01)
approx
?from pytest import approx
doingWe have already been using python functions for pytest
, without
really thinking about how they work. In Part 1.7 of Practical
Python,
functions are explained.
Convert the interactive evaluation here to a pytest
test.
Check your test(s) for coverage with
pytest --cov=pcost --cov-report=term-missing pcost.py