Writing automated tests for Python command-line apps and scripts

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ค. 2017
  • 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:
    - 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 P...
    FREE COURSE - "5 Thoughts on Mastering Python" dbader.org/python-mastery
    SUBSCRIBE TO THIS CHANNEL: dbader.org/youtube
    * * *
    ► Python Developer MUGS, T-SHIRTS & MORE: nerdlettering.com
    FREE Python Tutorials & News:
    » Python Tutorials: dbader.org
    » Python News on Twitter: / @dbader_org
    » Weekly Tips for Pythonistas: dbader.org/newsletter
    » Subscribe to this channel: dbader.org/youtube

ความคิดเห็น • 11

  • @kRySt4LGaMeR
    @kRySt4LGaMeR 6 ปีที่แล้ว +8

    Dude, your tutorials are amazing. You and Corey Schafer are the best. Thank you so much!

    • @realpython
      @realpython  6 ปีที่แล้ว +1

      You're welcome!

    • @portfedh
      @portfedh ปีที่แล้ว

      I second that. This is so useful and clear, and to the point.

  • @lohannasarah5054
    @lohannasarah5054 6 ปีที่แล้ว +2

    Very useful, thanks

    • @realpython
      @realpython  6 ปีที่แล้ว +1

      You're welcome!

  • @allgreatthings9608
    @allgreatthings9608 5 ปีที่แล้ว +3

    sorry kind of new to python
    Why are you sending variables in this way ? def move_file(root_folder: str , path: str) ?
    Wouldn't def move_file (root_folder , path) work in the same way ?
    Is this some sort of validation for a string ?

    • @randomguyUPSB
      @randomguyUPSB 5 ปีที่แล้ว +3

      It's not an improvement to functionality, but rather an improvement to maintainability.
      If you're making production code(code that will be read and potentially modified by others), you add type hints to reduce the possibility of others misunderstanding your code.
      Even for yourself it can be helpful to add type hints, if the project you're making is getting big and you simply can't remember everything every method does.
      So it does the same logic, but is easier to figure out if you read the same code after 2 years of not looking at it.

  • @ulissemini5492
    @ulissemini5492 5 ปีที่แล้ว +1

    thanks! i'm from go but this was useful

  • @brainstroem1
    @brainstroem1 6 ปีที่แล้ว +3

    *facepalm* so simple... thanks! i almost feel stupid now :))

    • @realpython
      @realpython  6 ปีที่แล้ว +1

      You're welcome! I'm glad the video was helpful. :-)