Unit test

In order to unit test this, we'll need to mock two external objects. We need a mock for the run() function in the subprocess module. We don't want to actually run the other process, but we want to be sure that the run() function is called appropriately from the make_files() function.

We also need to mock the Path class and the resulting Path object. These provide the filenames, and will have the unlink() method called. We need to create mocks for this so that we can be sure only the appropriate files will be unlinked by the real application.

Testing with mock objects means that we never run the risk of accidentally deleting useful files when testing. This is a significant benefit of using Python for this kind of automation.

Here's ...

Get Modern Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.