API Reference¶
fake_subprocess¶
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.fake_process.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
- call_count(command)¶
Count how many times a certain command was called. Can be used together with fake_process.any().
- Parameters:
command (
Union
[Sequence
[Union
[str
,Any
,PathLike
,Program
]],str
,Command
]) – lookup command- Return type:
int
- Returns:
number of times a command was called
- classmethod context()¶
Return a new FakeProcess instance to use it as a context manager.
- Return type:
- 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
[Sequence
[Union
[str
,Any
,PathLike
,Program
]],str
,Command
]) – allow to execute the supplied commandoccurrences (
int
) – allow multiple usages of the same command
- Return type:
None
- program¶
alias of
Program
- register(command, stdout=None, stderr=None, returncode=0, wait=None, callback=None, callback_kwargs=None, signal_callback=None, occurrences=1, stdin_callable=None)¶
Main method for registering the subprocess instances.
- Parameters:
command (
Union
[Sequence
[Union
[str
,Any
,PathLike
,Program
]],str
,Command
]) – register the command that will be fakedstdout (
Union
[str
,bytes
,None
,Sequence
[Union
[str
,bytes
]]]) – value of the standard outputstderr (
Union
[str
,bytes
,None
,Sequence
[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 stdinsignal_callback (
Optional
[Callable
])
- Return type:
ProcessRecorder
- register_subprocess(command, stdout=None, stderr=None, returncode=0, wait=None, callback=None, callback_kwargs=None, signal_callback=None, occurrences=1, stdin_callable=None)¶
Main method for registering the subprocess instances.
- Parameters:
command (
Union
[Sequence
[Union
[str
,Any
,PathLike
,Program
]],str
,Command
]) – register the command that will be fakedstdout (
Union
[str
,bytes
,None
,Sequence
[Union
[str
,bytes
]]]) – value of the standard outputstderr (
Union
[str
,bytes
,None
,Sequence
[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 stdinsignal_callback (
Optional
[Callable
])
- Return type:
ProcessRecorder
any()¶
For a non-exact matching, you can use the Any()
class that is available to
use via fake_subprocess.any
. This class can be used to replace a number
of arguments that might occur,
- class pytest_subprocess.utils.Any(*, min=None, max=None)¶
Wildcard definition class.
- Parameters:
min (
Optional
[int
])max (
Optional
[int
])