Visual Studio Code for Python Developers Transcripts
Chapter: Running and Debugging
Lecture: Using the Debug Console

Login or purchase this course to watch this video and the rest of the course contents.
0:00 There's one more tool I wanted to point out to you when it comes to debugging your applications in Visual Studio Code, and that's the Debug Console.
0:09 Let's go ahead and set our breakpoint back inside of the status router. I'm going to go ahead and start my debugging session again.
0:16 And I'm going to go ahead and issue a request using our sample.http file. Now I'm going to issue the request.
0:24 And notice here in this area at the bottom where the terminal is, there's a tab for Debug Console.
0:30 And what I can actually do here is I can type in the names of the variables that are in
0:33 scope and I can inspect and see what some of those values are equal to.
0:37 So for instance, if I wanted to take a look at the response, for instance, because the
0:41 response is in scope, notice it gives me some information about the object.
0:45 I can see this is a starlet responses response type, or it's an instance of that type. I could open and expand a little bit.
0:52 I can see, well, there's no body in there. There's the headers and some of these different types of things that are set.
0:59 But another thing we can do is actually alter some of these variables.
1:03 And we can actually change their values as we're going through the debugging session.
1:07 So maybe you want to see how your code reacts to when certain values are set. You can do it here in the Debug Console. So let me show an example.
1:14 If I go ahead and you just hit the Run button, notice that this should return an http 200 OK. So that's a successful request.
1:22 Let's go ahead and run it again. And now this time, what I'm going to do is I'm going to step over. I'm going to head back to the debug console.
1:27 And I'm going to go ahead and do a little bit of debugging. And I'm going to go ahead and do a little bit of debugging.
1:28 And I'm going to go ahead and do a little bit of debugging. I'm going to head over to the debug console. Let's say response.status is equal to 10.
1:37 I think 10 is a bad number. Let's set this to 400. I'm going to hit Enter. Now if I inspect this, or actually let's inspect it in the debug console.
1:45 I'm going to hit Response. Oops, didn't type that right. There we go. Let's hit Response. And now if I inspect it, I had done the status code.
1:54 I can see my status code is set to 400 because I changed it in the debug console. So I'm going to hit Enter.
1:58 And now if I inspect this, or actually let's inspect it in the debug console. I'm going to hit Response.
1:58 And now if I inspect this, or actually let's inspect it in the debug console. If I continue my debugging session, notice it says 400 bad requests.
2:04 Now maybe I have some middleware I want to test. Maybe I want to test the handler or maybe my unstartup shutdown operations
2:12 or whatever it is that you have going on inside of your framework. You have the option to intercept the debugging session,
2:18 change some of the values in the debug console, and see what happens as you continue debugging your application.


Talk Python's Mastodon Michael Kennedy's Mastodon