Modern Python Projects Transcripts
Chapter: Let's build a package
Lecture: Add tests
0:01 Let's go and add some tests. Here We have the test file with some tests that were created with the cookie cutter
0:11 template, so we can actually remove all of that. And let's go back to the old project and we can copy the test from here
0:17 We have to change a few things because we use the different file names. So from the CLI we import the main function and from the helpers we import the
0:37 rest. important, but unused. Okay, we'll use it in a moment. So let's search for the check function because we renamed it. Not check. Let me check.
0:53 Okay, this is how we call it, so we no longer have a check function. We have a main function and here as well, and I think we should be ready to go.
1:05 Let's go back to the terminal and let's run pytest and nothing happened because we
1:12 actually don't have pytest install, So pytest is installed in this file, but we never actually installed it.
1:19 First, let's remove this old version of pip because it's way too old and let's
1:25 try to install those packages, make sure you are inside the virtual environment and we
1:46 have some version conflicts. pytest mock requires pytest higher than five. But I have pytest 4 specified somewhere.
1:54 What we can do is to change the version in this file. But a much better idea is to actually repin all those dependencies to the latest version
2:03 So, let me quickly do that. We are going to remove all those versions here, and I'm going to rename this file to requirements_dev.in.
2:19 And now I am going to quickly install pip tools and run it so it pins the dependencies. And now we have the requirements_dev.txt with all the
2:43 dependency versions pinned. So, now we can tell pip to use this file, no more
3:04 errors, and we get the additional benefit that we use the latest version of our packages. Now we should be able to run pytest.
3:14 Great. So all nine tests are passing, but we got some warning here. Unknown config option: collect_ignore. If we search for this configuration option,
3:28 you can see that in the setup.cfg We're using some configuration option that it's probably no longer supported,
3:35 so, you can either check what it's doing and may be update it, or you can simply remove it. And this will make the warning go away.
3:44 Great. So we have all the tests passing, and now let's actually work on the documentation.