O'Reilly logo

Modern Python Cookbook by Steven F. Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create the database access module. This module will have the ElasticClient class definition. It will also have any additional definitions that this class needs.
  2. This recipe will use unittest and doctest to create a unified suite of tests. It will use the Mock class from unittest.mock, as well as json. Since this module is separate from the unit under test, it needs to import ch11_r08_load, which has the class definitions that will be tested:
        import unittest 
        from unittest.mock import * 
        import doctest 
        import json 
        import ch11_r08_load 
  1. Here's the overall framework for a test case. We'll fill in the setUp() and runTest() methods of this test below. The name shows that we're given an instance of ElasticClient, when we invoke ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required