There's more...

In the Mocking External Resources recipe in Chapter 9, Testing, we looked at ways to mock external resources so that we could write a unit test that wouldn't accidentally delete files. A test for the code in this recipe needs to mock the filesystem resources by mocking the Path class. Here's how the unit test would look, starting with a high-level outline of the test class:

    import unittest 
    from unittest.mock import * 
 
    class GIVEN_get_config_WHEN_load_THEN_overrides(unittest.TestCase): 
        def setUp(self): 
 
        def runTest(self): 

This provides a boilerplate structure for a unit test. Mocking a Path becomes rather complex because of the number of distinct objects involved. Here's a summary of what kinds of object creations occur:

Get Modern Python Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.