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
Metadata
Release files for subprocess-mock 0.4.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| subprocess_mock-0.4.5.tar.gz | 28.2 kB | Without provenance | Details for subprocess_mock-0.4.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| subprocess_mock-0.4.5-py3-none-any.whl | Python 3 | none | any | Details for subprocess_mock-0.4.5-py3-none-any.whl |
Total release size: 57.0 kB
Release files / subprocess_mock-0.4.5.tar.gz
| Download URL | subprocess_mock-0.4.5.tar.gz |
|---|---|
| Size | 28.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb5b0929704c213e1e888fa7322bae6357f5c2e4c766fc438c3846d6d2034046
|
|
BLAKE2b-256 checksum How to use checksums |
6e286767d9e9d135f7e657661d42c655484d743f4d5bbad3e4104c9daa27313a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / subprocess_mock-0.4.5-py3-none-any.whl
| Download URL | subprocess_mock-0.4.5-py3-none-any.whl |
|---|---|
| Size | 28.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd360d08b91a3783d92a6b071982b5a97a6a4fc4c51ff5747767d8e88feeb400
|
|
BLAKE2b-256 checksum How to use checksums |
905aea7c98eff0a0319b2583bb2f352744c9cc33454b9e76a71ab5ca4c98805c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for subprocess-mock 0.4.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.