Writing automated tests for Python command-line apps and scripts

Опубликовано: 23 October 2024
на канале: Real Python
36,036
424

https://dbader.org/python-tricks ► Write clean and testable Python command line apps and learn by example

Two techniques for writing automated tests for your Python command-line applications and scripts.

In this video you'll see how to structure the entry points of your Python command-line scripts in order to make them easier to test with unit and integration tests using Python's unittest library.

You'll also learn how to use "mocking" and the @mock.patch decorator in the unittest library to put functions that have side-effects on the filesystem under test.

See examples of how these techniques are implemented in the project I show in the video:

https://github.com/dbader/photosorter

This project gives you a blueprint for writing testable Python scripts and shows you how to run these tests on a build server (Jenkins, TravisCI, CircleCI, ...) using the pytest test runner.

Interested in the mypy type checker and the Python type annotations that appear in the video? This tutorial will help you get set up:

   • Type-Checking Python Programs With Ty...  

FREE COURSE – "5 Thoughts on Mastering Python" https://dbader.org/python-mastery

SUBSCRIBE TO THIS CHANNEL: https://dbader.org/youtube

* *

► Python Developer MUGS, T-SHIRTS & MORE: https://nerdlettering.com

FREE Python Tutorials & News:
» Python Tutorials: https://dbader.org
» Python News on Twitter:   / @dbader_org  
» Weekly Tips for Pythonistas: https://dbader.org/newsletter
» Subscribe to this channel: https://dbader.org/youtube