Testpath is a collection of utilities for Python code working with files and commands. It contains functions to check things on the filesystem, and tools for mocking system commands and recording calls to those. The current version is 0.6.0.
pip install testpathVerified import paths — ran on the pinned version, not inferred.
Demonstrates asserting the existence of a temporary file and then using `testpath.assert_calls` to mock an external system command during a function call.
Be aware of the global nature of command mocking. For highly concurrent tests, consider alternative mocking strategies that are process-isolated or carefully manage `PATH` manipulation across test setups/teardowns, though this is difficult with `testpath`'s approach. Ensure mocks are properly torn down.
Use `testpath` for mocking external commands only. For mocking Python functions, classes, or methods, use Python's built-in `unittest.mock` library or other Python-specific mocking frameworks.
pip install testpath
Use testpath.assert_path_exists('/path/to/check') instead.Import MockCommand directly from testpath using: from testpath import MockCommand
Provide the command name when creating MockCommand, for example: with testpath.MockCommand('ls') as mock_ls:No dependency data recorded yet.