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.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
-
any
¶ alias of
pytest_subprocess.utils.Any
-
call_count
(command)¶ Count how many times a certain command was called. Can be used together with fake_process.any().
-
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.
-
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
[Union
[str
,Any
]],Tuple
[Union
[str
,Any
], …],str
,Command
]) – 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
-
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
]) –