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. We just run pytest against our _all_tests.py file here and everything is super.
0:08 Let's just see how this might go if we, say, weren't inside a PyCharm. So let's go over to the directory here
0:14 and make sure we activate the virtual environment so everything's going to work that's of course required.
0:20 But now I should be able to type pytest _all_tests.py and let's just disable the warnings there's some lower level libraries we can't fix
0:28 that are issuing some warnings so just let's see what's going on. This should work just the same as if I go over here and press this, right?
0:37 No. No module named pypi.org. So we have a couple of options. One, we could actually convert our website into a package, and then install it
0:46 and that problem just goes away. The other thing is, we can just add a little line of code here to fix this. So why does it run here, and not there
0:54 when basically the same command is entered? It's because if you look at the run configuration the content routes and source routes
1:02 are added to the Python path. Namely, this folder up here is added to the Python path, so pypi.org and test and so on, exist and can be imported.
1:13 Well, that's actually pretty easy to do. You had to do it earlier but I tried to avoid talking about it before, right here.
1:20 So this is really all we have to do is we add this little block of code that says go and find out what the containing folder is
1:28 and then add it at the front of the Python path. So if we go over here to our all models and we put this at the top, like so
1:36 it doesn't quite look as nice it makes us get a little grunt in here but you know what? Now, if we try this again, beautiful. It's working great.
1:45 And of course it's sill going to work inside PyCharm, just like that. So it's a little bit frustrating the way that wasn't working before
1:53 but as you can see we could either make this a package and then install it for development which is not a big deal but a little complicated
2:00 or we just put this one line here so there's no action other than running this file necessary. There's probably other options
2:07 I'm sure there are other options but here's two that'll work pretty well.


Talk Python's Mastodon Michael Kennedy's Mastodon