Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Setting Up a New Python TDD Project

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.

00:00 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 pippip install pytest. After that’s complete, we have all our dependencies. Next, let’s create our files.

00:20 Because we’re going to be creating a data structure, or a type of data structure, I’m going to call my overall project ds for data structure.

00:29 I’m going to say mkdir (make directory) ds, for data structure. Then I’m just going to cd into that directory.

00:39 And there’s no files in here. Now, I’m going to create some subdirectories. I’m going to create another subdirectory called ds and a directory called tests.

00:56 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.

01:09 So, inside of ds/ what I’m going to do is I’m just going to say touch ds/__init__.py,

01:18 and I’m going to say touch ds/stack.py.

01:26 So, those two files—the stack.py is where we’re going to be implementing our stack data structure, and this __init__.py—that basically creates a package inside that directory.

01:42 So the ds/ directory basically becomes a package with this __init__.py. Okay. And then I need a file to actually run our tests against.

01:52 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 test_ (test underscore).

02:10 So if we were like, for example, testing a queue, we would say test_queue. If we were testing a binary tree, we would say test_binary_tree. So here’s all the files we need.

02:23 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:45 And you can see, here is DS/ and here’s the subdirectory ds/, for data structure. And here’s my stack. And then under tests/, here’s this.

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.

tsathyanarayanan on Nov. 26, 2019

Thanks for the video, it is really good.

Become a Member to join the conversation.