Search⌘ K
AI Features

Refactor and Improve the Test

Explore how to refactor your Django test methods by adding docstrings to document and clarify test purposes. Understand the benefit of descriptive test documentation within Django's unit testing framework to identify failures more easily.

In this lesson, we refactor our test methods. The purpose of this refactoring is to improve the method by making it more descriptive. We use the Python document string also called the docstring for this.

What are docstrings?

To add comments to our code in Python, we use the # symbol, as shown below:

def sayHello():
    # prints hello world to the screen
    print("Hello World")

We can also use docstrings to add comments. ...