In this lesson, you’ll get familiar with the recommended workflow for solving the challenge, along with the tooling to help you achieve that goal. Both are pretty straightforward. Below, you’ll find more details about how to leverage the popular pytest
framework to evaluate your solution, track your progress, and reveal helpful resources when you get stuck.
Project Overview
If you’ve followed the previous step, then you should already have a code editor open with the scaffolding for your Python project. Here’s what its directory structure looks like:
wordcount/
│
├── src/
│ └── wordcount.py
│
├── tests/
│ └── (...)
│
├── README.md
├── pyproject.toml
└── requirements.txt
The highlighted line represents the single most important file, wordcount.py
, which you’ll edit to implement your solution. It’s the main Python script that emulates the Unix wc
command. In the beginning, this file will be mostly empty, but you’ll gradually add more code to it as you solve the subsequent tasks.
Note: Don’t rename this file! If you do, then the tests won’t be able to locate it, and you’ll encounter errors when you try to run them.
You can create additional modules and packages as you see fit, but it’s not strictly necessary. The sample solution provided later will limit itself to only one file.
The tests/
folder contains the internal machinery for validating the acceptance criteria of the tasks ahead of you. You can completely ignore it. But, at the same time, feel free to use this folder as a container for your own unit tests if you find them beneficial or if you want to follow the test-driven development (TDD) approach.
Note: To use pytest
the usual way you might be used to, disable the Real Python plugin:
(venv) $ pytest -p no:realpython
This will let you run your own unit tests without any interference from the automation tool.
The remaining files contain your project’s configuration, dependencies, and a brief description. You don’t need to worry about these either.
Task Instructions
This coding challenge consists of multiple tasks that you must complete in order. At first, only the first task is unlocked, meaning you can’t move on to the next one until all respective acceptance criteria are met. To quickly bring up the instructions for your current task, you can type the following command in the terminal:
(venv) $ pytest --task
Depending on how far you’ve progressed in solving the challenge, it’ll open the lesson that corresponds to the current task in your default web browser and display its URL in the terminal, just in case.
Note: If you’re using GitHub Codespaces, then this command should work out of the box. If you’re working on a local computer, then remember to activate your project’s virtual environment first if you haven’t already.
Next up, you’ll learn how to get automated feedback about your solution and reveal all tasks along with their statuses in a human-readable format.
Progress Tracking
To verify the correctness of your solution up to and including the current task, you can check a subset of the acceptance criteria by running pytest
with no arguments or options:
(venv) $ pytest
This will display a color-coded tree view of the tasks broken down into their individual acceptance criteria with descriptive names and their statuses. You only get to see the details of the unlocked tasks:

A task is considered completed when all its acceptance criteria become satisfied, as indicated by a green checkmark. Completing a task unlocks the next one along with its own acceptance criteria.
Note: While solving your current task, you may inadvertently break one of the acceptance criteria for an earlier task that was previously successful. To ensure that your solution is correct, you won’t be able to advance until you’ve met the criteria for all unlocked tasks so far.
When you’re focused on solving a single task, you can narrow down the set of acceptance criteria to run by specifying the task number, like so:
(venv) $ pytest -k 5
(venv) $ pytest -k 10
(venv) $ pytest -k 01
This will only run the acceptance criteria associated with this task. To speed up your development cycle even further, you can run only the previously failed acceptance criteria with this command:
(venv) $ pytest --last-failed
Finally, if you’d like to start the entire challenge from scratch, then you can reset your progress by clearing the pytest
cache:
(venv) $ pytest --cache-clear
Running this command will bring you back to the first task, locking the subsequent tasks. However, it won’t delete your code or any changes you’ve made, which will remain intact.
But what if you hit a roadblock and can’t get past it? You’re about to find out.
Helpful Resources
After a few unsuccessful attempts, pytest
may suggest one or more resources for you to check out to help you get unblocked:
$ pytest
⋮
💡 Need help? Check out these resources:
• Python Comments Guide
• Writing Comments in Python
These are clickable links pointing to valuable resources, including tutorials, video courses, podcast episodes, and learning paths. These can provide insights and examples to help you overcome any obstacles you may encounter on your way to successfully completing the task at hand.
What’s Next?
With these technical details out of the way, it’s time to tackle your first task!
🎯 Continue to the next lesson to get started with the challenge.