Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Guided: Test Driven Development While Building a Set Class - Python 3

This hands-on lab is designed to help you practice test driven development while building a version of the Set data type in C#. A series of guided steps will walk you through the process of Test Driven Development which include writing a test, implementing functionality, and refactoring to maintain green to green test coverage. By the end of the lab, you will have demonstrated a strong understanding of the Test Driven Development process in Python.

Lab platform
Lab Info
Last updated
Sep 21, 2025
Duration
1h 5m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Implement Set Contains Following TDD

    In this section, you will implement the contains method for a MySet class. This will require making minimal changes to the add method. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The files you will be working on throughout this lab is my_set.py and my_set_test.py. The objective is to create a functioning MySet class that can be used like one would expect a Set object would be. However, we will not be focused on performance like a traditional set.

    The solution file for a task that is implementing functionality can be found in soln/step1/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

    To run tests, use the command python3 my_set_test.py.

  2. Challenge

    Implement Set Add Following TDD

    In this section, you will implement the add method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step2/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

  3. Challenge

    Implement Set Remove Following TDD

    In this section, you will implement the remove method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step3/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

  4. Challenge

    Implement Set Size Following TDD

    In this section, you will implement the size method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step4/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

  5. Challenge

    Implement Set Clear Following TDD

    In this section, you will implement the clear method for a MySet class. While doing this, we will follow steps that we would take when building out this feature using Test Driven Development (TDD).

    For reference, this process involves small steps to achieve the end goal. We write a test, see it fail, implement basic functionality to get to a green state, and perform refactors as fit. When we perform refactors we go from a green to green state, this means that all of our tests pass when we start and end a refactor.

    The solution file for a task that is implementing functionality can be found in soln/step5/{corresponding task}/my_set.py.

    The solution file for a task that is implementing a test can be found in soln/step5/my_set_test.py.

    It is important to note that if the task you are working on asks you to implement a test, you will be working in the my_set.py file. Otherwise, you will be implementing functionality in the my_set_test.py.

About the author

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight