API Reference¶
The main entrypoint class for all fake_subprocess
operations is the
FakeProcess
class. This class is instantiated and returned when the
fake_subprocess
fixture is being used.
-
class
pytest_subprocess.core.
FakeProcess
¶ Main class responsible for process operations
-
allow_unregistered
(allow)¶ Allow / block unregistered processes execution. When allowed, the real subprocesses will be called. Blocking will raise the exception.
- Parameters
allow (
bool
) – decide whether the unregistered process shall be allowed- Return type
None
-
classmethod
context
()¶ Return a new FakeProcess instance to use it as a context manager.
- Return type
-
classmethod
keep_last_process
(keep)¶ Keep last process definition from being removed. That can allow / block multiple execution of the same command.
- Parameters
keep (
bool
) – decide whether last process shall be kept- Return type
None
-
pass_command
(command, occurrences=1)¶ Allow to use a real subprocess together with faked ones.
- Parameters
command (
Union
[List
[str
],Tuple
[str
, …],str
]) – allow to execute the supplied commandoccurrences (
int
) – allow multiple usages of the same command
- Return type
None
-
register_subprocess
(command, stdout=None, stderr=None, returncode=0, wait=None, callback=None, callback_kwargs=None, occurrences=1, stdin_callable=None)¶ Main method for registering the subprocess instances.
- Parameters
command (
Union
[List
[str
],Tuple
[str
, …],str
]) – register the command that will be fakedstdout (
Union
[str
,bytes
,None
,List
[Union
[str
,bytes
]],Tuple
[Union
[str
,bytes
], …]]) – value of the standard outputstderr (
Union
[str
,bytes
,None
,List
[Union
[str
,bytes
]],Tuple
[Union
[str
,bytes
], …]]) – value of the error outputreturncode (
int
) – return code of the faked processwait (
Optional
[float
]) – artificially wait for the process to finishcallback (
Optional
[Callable
]) – function that will be executed instead of the processcallback_kwargs (
Optional
[Dict
[str
,Any
]]) – keyword arguments that will be passed into callbackoccurrences (
int
) – allow multiple usages of the same commandstdin_callable (
Optional
[Callable
]) – function that will interact with stdin
- Return type
None
-