UNB/ CS/ David Bremner/ teaching/ cs2613/ labs/ Lab 15

Before the Lab

Read

Background


Questions

Time
10 minutes
Activity
Discussion

Getting Started

Pytest

Time
15 minutes
Activity
Demo
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'
[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 ====================

Lists and Pytest

Time
25 minutes
Activity
Individual programming from template

Files

Time
35 minutes
Activity
Individual programming, synthesis
def test_sum():
    from pytest import approx
    assert sum==approx(44671.15,abs=.01)

Functions

Time
25 minutes
Activity
Individual programming, modify previous solution

We 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.

Before next lab

Read