Subprocess Mock
Project description
Subprocess Mock
Mock objects for the standard library’s subprocess module
pip install subprocess-mock
Installation in a virtual environment is recommended.
Example Usage
Use the functions defined in the subprocess_mock.functions module (and also exposed in the subprocess_mock namespace) to patch subprocess module functions in unit tests.
>>> import pathlib
>>> import subprocess
>>> import subprocess_mock
>>> from unittest.mock import patch
>>>
>>> new_file = pathlib.Path("testfile.txt")
>>> new_file.exists()
False
>>> # Test: call a process with a mock.patched subprocess.run
>>> # No Process is called,
>>> # but a subprocess.CompletedProcess instance is returned.
>>>
>>> with patch("subprocess.run", new=subprocess_mock.run):
... run_result = subprocess.run(["touch", str(new_file)])
...
>>> run_result
CompletedProcess(args=['touch', 'testfile.txt'], returncode=0)
>>> new_file.exists()
False
>>>
>>> # Counter-test: call the process without patching subprocess.run
>>> # The process is called with normal effects.
>>>
>>> run_result = subprocess.run(["touch", str(new_file)])
>>> new_file.exists()
True
>>>
Further reading
Please see the documentation at https://blackstream-x.gitlab.io/subprocess-mock for detailed usage information.
If you found a bug or have a feature suggestion, please open an issue here
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
subprocess-mock-0.4.3.tar.gz
(28.1 kB
view details)
Built Distribution
File details
Details for the file subprocess-mock-0.4.3.tar.gz
.
File metadata
- Download URL: subprocess-mock-0.4.3.tar.gz
- Upload date:
- Size: 28.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23b92c27707eef79d8cef3837e26180e2852f81d63ef585c36b0a445285526bb |
|
MD5 | bddf226e5c2c99171dd1ef0db507d7b4 |
|
BLAKE2b-256 | c97546fc02f2ed423a943fa524413f9888976dd3782a3eaea22af28f14a62779 |
File details
Details for the file subprocess_mock-0.4.3-py3-none-any.whl
.
File metadata
- Download URL: subprocess_mock-0.4.3-py3-none-any.whl
- Upload date:
- Size: 28.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b656a69d8e221562b863ee6cbb1cb76e4e67dc0349f0413079f18668cbcb5480 |
|
MD5 | 165b1edd3751cd1a96ca2e3df8e6626a |
|
BLAKE2b-256 | 9285312c17b0b68aa5ab09e98ee3619375dc27ef7922890d579b08fd87afc3ea |