Python for the .NET developer Transcripts
Lecture: Concept: A basic pytest test
0:00 Let's talk quickly about building a basic Pytest test
0:04 before we get too deep into testing for errors.
0:07 All we have to do if we want to write a test
0:09 is we have to define a function
0:10 which has the word test_
0:12 and then whatever you want.
0:13 Here we wrote test_run_me_wrong
0:15 because we saw this still uses the dependencies.
0:18 But as long as the name has a test, underscore
0:21 and are ready to go, Pytest will try to run it
0:24 and then we make our asserts
0:26 using Python's built-in assert statement here.
0:29 So, assert, all guitar.styles == electric
0:33 for all guitars in, for each guitar in guitars.
0:37 Really, really clean, this is a simple way
0:39 to write a test, as we saw it's not sufficient
0:41 because, well, that goes to the database
0:43 and does the walking and the other dependent things
0:46 that we probably want to control and factor out of our test.
0:49 But this is the basic anatomy of creating a simple test.