Oct 09: Quiz3, Testing Modules
Learning Objectives
After today's class, you should be able to:
- Explain how to use the
from
keyword in animport
statement. - Describe how functions in a test module use
assert
statements.
Announcements¶
- Due today: HW7 Reflection
- Read Ch 8 (due Tuesday)
- Only 5 sections this week!
- Mid-Eval Canvas survey (due Friday)
- Coming soon: Project 1 (due Nov 01)
HW7 Debrief¶
- Using
while True
andbreak
(orreturn
) random.randint()
versusrandom.random()
print_stats()
should have used afor
loop!- Use
if __name__ == "__main__":
for testing
Quiz 3¶
- Log in as
student
- Only two windows:
- Thonny
- Web browser
- Web traffic monitored
- Log out when finished
Ch08 Preview¶
- Difference between a script and a module
- Importing a module from the same folder
- Optional:
from
moduleimport
function - The
__pycache__
folder (auto generated)
Example tests for HW7.2
An assert
statement is used to see if each function call returns the expected tuple.
test_division.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Example tests for HW7.5
The capsys
argument (provided by pytest
) automatically captures system output and error messages.
Remember that placing multiple string literals next to each other automatically combines them into a single string.
test_even_more.py | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|