Skip to content

Add python-cli-testing materials folder - #973

Merged
realpython-bot merged 2 commits into
masterfrom
maintenance/python-cli-testing-20261201
Dec 1, 2026
Merged

realpython-bot merged 2 commits into
masterfrom
maintenance/python-cli-testing-20261201

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Adds the companion code for 4 Techniques for Testing Python Command-Line (CLI) Apps, under the standing rule that every tutorial with runnable code gets a materials folder and a sample-code opt-in.

Files

  • testapp.py: the tutorial's starting app, with its deliberate bugs. Running it raises KeyError: 'parents', as the article shows. The run loop sits under an if __name__ == "__main__": guard so pytest can import the module.
  • test_testapp.py: the article's generate_initial_transform_parameters fixture and test_initial_transform().
  • requirements.txt: pytest==9.1.1, the same pin as the article's dependencies field.
  • README.md: setup and usage. The Python 3.10 floor comes from pytest 9.1.1's Requires-Python (vermin reports 3.0 for the code itself).

The mock snippets aren't included. They patch a hypothetical outside_module and need pytest-mock, which the article doesn't pin.

Verification (Python 3.14, venv built from requirements.txt)

  • python testapp.py ends in KeyError: 'parents', which matches the article's traceback.
  • pytest: 1 passed (nodict), 1 failed (dict). That's the intended state before the Unit Test Exercise.
  • With the exercise solution patched into initial_transform(), both tests pass.
  • ruff format --check, ruff check (0.14.1), and dircheck.py all pass.

Links

🤖 Generated with Claude Code

realpython-bot and others added 2 commits December 1, 2026 13:01
Companion code for the tutorial 4 Techniques for Testing Python
Command-Line (CLI) Apps: the buggy starting app and its pytest unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@realpython-bot
realpython-bot merged commit b81ca4b into master Dec 1, 2026
1 check passed
@realpython-bot
realpython-bot deleted the maintenance/python-cli-testing-20261201 branch December 1, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant