Skip to main content

MockProcess is a mock for the subprocess module to be used in your unit tests. Right now it only supports the check_output method, but eventually popen will be supported as well.

It is used via a context manager. Here’s a basic example

>>> import subprocess
>>> import unittest
>>> from mockprocess import MockCheckOutput
>>> class Test(unittest.TestCase):
...     def test_simple(self):
...         with MockCheckOutput('hello\n'):
...             output = subprocess.check_output(['/bin/echo', 'hello'])
...         self.assertEqual(output, 'hello\n')
...

If you need to test how you handle errors, you can set an exit code as well.

>>> import subprocess
>>> import unittest
>>> from mockprocess import MockCheckoutput
>>> class Test(unittest.TestCase):
...     def test_exception(self):
...         try:
...             with MockCheckOutput('hello\n', exit_code=127):
...                 subprocess.check_output(['/bin/false'])
...         except subprocess.CalledProcessError as exp:
...             pass
...         else:
...             self.fail('exception was not raised')

Release files for mockprocess 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mockprocess 0.2
File Size Uploaded
mockprocess-0.2.tar.gz 2.2 kB Details

Release files / mockprocess-0.2.tar.gz

Download URL mockprocess-0.2.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
305ac8a0f36713af528368676bd1c015d9f49a8853a73dc531b68ef63726aa40
BLAKE2b-256 checksum
How to use checksums
61a6f824b0b8f00273a939b65b08b7c419c89c07b77e2247d196d1d14fb59c10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page