Skip to main content
Solving on leetcode.com means round-tripping between browser tabs. A generated practice environment moves that loop into your terminal: every problem ships with a parametrized pytest suite, so testing your solution is one command in your own editor, with your own debugger and no page reloads.

One-time setup

The package pulls in loguru, which the suites use to log every case. pytest is not a package dependency, so install it in the same environment. Or use uv: uv tool install leetcode-py-sdk plus uv pip install pytest in your active venv.

Generate a problem, see red

The suite runs immediately and mostly fails, because solution.py arrives as a TODO stub:
Every failing case is named by its parametrized id, and the assertion output shows the inputs and the expected result, so you know exactly which contract you broke.

Implement, go green

Replace the TODO in solution.py with your approach:
Rerun the suite:
Never edit the tests to make them pass. The suite is the contract; the 10+ cases per problem include the LeetCode examples plus edge cases (empty results, negatives, duplicates, boundary sizes), so green here means green, not “green for the two examples I checked”.

Iterate on one case at a time

Mid-debug, you want one case, not eighteen. pytest flags that earn their keep on these suites:
With -s, each case logs its inputs and verdict:

A whole practice tree works the same

Generate a collection and plain pytest discovers every suite under the current directory:
Pick your set in Collections or browse the Catalog.

Where to go next

Last modified on August 25, 2026