Modern Python Projects Transcripts
Chapter: Let's build a package
Lecture: Add tests

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's go and add some tests.
0:03 Here We have the test file with some tests that were created with the cookie cutter
0:10 template, so we can actually remove all of that.
0:13 And let's go back to the old project and we can copy the test from here
0:16 We have to change a few things because we use the different file names.
0:29 So from the CLI we import the main function and from the helpers we import the
0:36 rest. important, but unused. Okay,
0:41 we'll use it in a moment.
0:43 So let's search for the check function because we renamed it.
0:48 Not check. Let me check.
0:52 Okay, this is how we call it,
0:53 so we no longer have a check function.
0:55 We have a main function and here as well,
1:02 and I think we should be ready to go.
1:04 Let's go back to the terminal and let's run pytest and nothing happened because we
1:11 actually don't have pytest install, So pytest is installed in this file,
1:15 but we never actually installed it.
1:18 First, let's remove this old version of pip because it's way too old and let's
1:24 try to install those packages, make sure you are inside the virtual environment and we
1:45 have some version conflicts. pytest mock requires pytest higher than five.
1:50 But I have pytest 4 specified somewhere.
1:53 What we can do is to change the version in this file.
1:58 But a much better idea is to actually repin all those dependencies to the latest version
2:02 So, let me quickly do that.
2:05 We are going to remove all those versions here,
2:10 and I'm going to rename this file to requirements_dev.in.
2:18 And now I am going to quickly install pip tools and run it so it pins
2:22 the dependencies. And now we have the requirements_dev.txt with all the
2:42 dependency versions pinned. So, now we can tell pip to use this file, no more
3:03 errors, and we get the additional benefit that we use the latest version of our
3:07 packages. Now we should be able to run pytest.
3:13 Great. So all nine tests are passing,
3:16 but we got some warning here.
3:19 Unknown config option: collect_ignore.
3:23 If we search for this configuration option,
3:27 you can see that in the setup.cfg
3:29 We're using some configuration option that it's probably no longer supported,
3:34 so, you can either check what it's doing and may be update it,
3:38 or you can simply remove it.
3:39 And this will make the warning go away.
3:43 Great. So we have all the tests passing,
3:45 and now let's actually work on the documentation.