Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Testing web apps
Lecture: Running tests outside of PyCharm

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So it looks like everything is working great.
0:02 We just run pytest against our file here
0:05 and everything is super.
0:07 Let's just see how this might go
0:08 if we, say, weren't inside a PyCharm.
0:11 So let's go over to the directory here
0:13 and make sure we activate the virtual environment
0:16 so everything's going to work that's of course required.
0:19 But now I should be able to type pytest
0:23 and let's just disable the warnings
0:24 there's some lower level libraries we can't fix
0:27 that are issuing some warnings
0:28 so just let's see what's going on.
0:30 This should work just the same as
0:32 if I go over here and press this, right?
0:36 No. No module named
0:39 So we have a couple of options.
0:40 One, we could actually convert our website
0:43 into a package, and then install it
0:45 and that problem just goes away.
0:47 The other thing is, we can just add
0:49 a little line of code here to fix this.
0:51 So why does it run here, and not there
0:53 when basically the same command is entered?
0:55 It's because if you look at the run configuration
0:58 the content routes and source routes
1:01 are added to the Python path.
1:03 Namely, this folder up here is added
1:06 to the Python path, so
1:08 and test and so on, exist and can be imported.
1:12 Well, that's actually pretty easy to do.
1:15 You had to do it earlier
1:16 but I tried to avoid talking about it before, right here.
1:19 So this is really all we have to do
1:21 is we add this little block of code that says
1:24 go and find out what the containing folder is
1:27 and then add it at the front of the Python path.
1:31 So if we go over here to our all models
1:32 and we put this at the top, like so
1:35 it doesn't quite look as nice
1:37 it makes us get a little grunt in here
1:38 but you know what?
1:39 Now, if we try this again, beautiful.
1:43 It's working great.
1:44 And of course it's sill going to work
1:46 inside PyCharm, just like that.
1:48 So it's a little bit frustrating the way
1:51 that wasn't working before
1:52 but as you can see we could either
1:54 make this a package and then install it for development
1:57 which is not a big deal but a little complicated
1:59 or we just put this one line here
2:01 so there's no action other than running this file necessary.
2:05 There's probably other options
2:06 I'm sure there are other options
2:07 but here's two that'll work pretty well.