Skip to content

Python Mocks! or "Fake it until you Make it"

Photo of Dave Voutila
Hosted By
Dave V.
Python Mocks! or "Fake it until you Make it"

Details

Python is great for rapidly building apps that integrate with various systems and services whether it's scraping websites with Scrapy or persisting data with SQL Alchemy.

But it's also easy to make unit testing your app pretty challenging!

Good News: a lot of the time you can fake it with mocks! Mocks let us easily isolate and unit test our application logic in a variety of ways by making fake instances of objects and even Python functions. And the best part? This isn't unique to Python and will make you a better programmer in a variety of languages since mock libraries exist for most these days!

In this session, we'll give you a crash course in Python mocks so you can simplify and improve your unit tests...or maybe even write tests you didn't think were possible! It will be split into two parts about 25-30m each and be very real world code-example driven:

Mocks 101 - Into to Mocks - Presented by Dave V

  • Mocking Python objects
  • Patching functions/methods

Mocks 201 - Mocking the Hard Stuff - Presented by Juan G

  • Advanced Python stuff to mock
  • Mocking Python decorators

For anyone brand new to mocks looking to get started, Python's "batteries included" approach means a mock module right in the standard libraries since Python 3.3 (https://docs.python.org/dev/library/unittest.mock.html)! For 2.7 users, you can check out the "mock" module (https://pypi.python.org/pypi/mock), which is the basis for the "unittest.mock" standard library.

Also, Ana Balica's presentation at PyCon2016 entitled "To Mock or Not To Mock" covers some of what we'll be talking about if you'd like a head start:

https://youtu.be/KYG5C1CEkOk

Special thanks to the folks at Logic Supply (https://www.logicsupply.com) who have agreed to host us for this week. Also, free pizza will be provided!

Photo of Burlington Python group
Burlington Python
See more events
Logic Supply
35 Thompson Street · South Burlington, VT