In this lesson you’ll set up a new Python project, which is used to teach you TDD. Therefore, dependecies are installed and the project structure is generated.
Setting Up a New Python TDD Project
One of the first things we should do is install any dependencies. Because we’re using
pytest, we should go ahead and install that. I’m going to be doing that using
pip install pytest. After that’s complete, we have all our dependencies. Next, let’s create our files.
So now I have a directory called
ds and a directory called
tests. Now, the directory called
tests is going to house our test files, and the directory called
ds is going to contain the stack data structure.
Our files are to go in the
tests/ directory, so I’m going to say
touch tests/—and I’m going to call this file
test_stack.py. Now, when you’re using
pytest, any file that you want to test has to be prefixed with the word
Now, there’s a Unix command called
tree—I can type this in and basically it lets you see the files that we created in a tree format. So, this is the package right here—the data structure package—that contains the
stack file, and then here’s our test. Okay? And so now it’s ready to start coding, and so I’m going to open up my code editor.
02:55 Now, what I like to do when I’m doing test driven development, I like to split these files side-by-side so that as you’re writing your tests you can kind of see the implementation side-by-side. Okay. So with that, let’s go ahead and get started.
Become a Member to join the conversation.