Explore the Recommended Workflow

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.

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.

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:

Shell
(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.

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:

Shell
(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:

Hierarchy of Tasks and Their Acceptance Criteria
Hierarchy of Tasks and Their Acceptance Criteria

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.

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:

Shell
(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:

Shell
(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:

Shell
(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:

Shell
$ 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.

Become a Member to join the conversation.