Python for .NET Developers Transcripts
Chapter: Testing
Lecture: Concept: A basic pytest test

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's talk quickly about building a basic Pytest test before we get too deep into testing for errors. All we have to do if we want to write a test
0:10 is we have to define a function which has the word test_ and then whatever you want. Here we wrote test_run_me_wrong
0:16 because we saw this still uses the dependencies. But as long as the name has a test, underscore and are ready to go, Pytest will try to run it
0:25 and then we make our asserts using Python's built-in assert statement here. So, assert, all guitar.styles == electric
0:34 for all guitars in, for each guitar in guitars. Really, really clean, this is a simple way to write a test, as we saw it's not sufficient
0:42 because, well, that goes to the database and does the walking and the other dependent things
0:47 that we probably want to control and factor out of our test. But this is the basic anatomy of creating a simple test.

Talk Python's Mastodon Michael Kennedy's Mastodon