Python for .NET Developers Transcripts
Chapter: Testing
Lecture: Python app under test

Login or purchase this course to watch this video and the rest of the course contents.
0:00 You saw the C# version now let's see the Python version of just the app and the library. Of course, we're going to write the test
0:08 and put all of that stuff in place but here we have the guitar app and here we have the lib that we talked about before so we have our guitar class
0:16 and down here we have the function that given a style, which is a string and it will return a list of guitars.
0:23 First off, we're going to lowercase the style we'll log out a little bit of information here. The log oh yeah the log is down at the bottom, down here
0:32 and of course it's just going to say print out just like we saw before. Some color output and we also have, if we go back up here
0:38 we have the get the guitars from the DB and down here we have a function which simulates getting data from the database and of course prints out
0:47 this should be shown in the app but again, not when we're actually trying to do testing cause that would mean we're depending on a dependency
0:54 which we want to mock out or something to that effect. Alright, well lets go ahead and run the app here see what we got. Should look pretty familiar
1:02 I want to see an electric guitar alright, here are your eight options and notice, here's your log and here's your note
1:10 that hey we're going to the database. You can see acoustic. See one write one, but of course we're using our dependencies and in the app
1:18 that's exactly what we want. In the test, it's exactly what we want to avoid. So this is the code that we're starting from for this chapter
1:25 and our goal is to write some tests that basically, the same test that we had before tests that we can filter for a particular type of guitars
1:33 tests that we can get all the guitars and tests that there's an error if we try to access a guitar that's not right. Let's actually take this out
1:42 so we can maybe discover a bug that way it just introduced and test that with out Python code and our pytest test.

Talk Python's Mastodon Michael Kennedy's Mastodon