testing
ActionStepTestCase
¶
Bases: BaseModel
Defines a test case for an action.
Useful in the parametrization of several use cases for an action.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Unique name for the test case. This is used as the identifier for a test case so that test failures may be easier to spot. |
py_file |
str
|
Path to the python file to run. |
inputs |
dict[str, str]
|
|
exit_code |
int
|
The expected exit code (default: 0). |
expected_stdout |
str
|
The expected stdout (default: empty). |
errors |
list[str]
|
Errors may be noisy, specify strings that are expected to be in stderr in an array of strings. |
outputs |
list[str]
|
|
file_write_side_effect |
Any | None
|
Defaults to |
Source code in m/testing/testing.py
BlockNetwork
¶
Bases: socket
Implements a socket that blocks all network calls.
Source code in m/testing/testing.py
__init__(*args, **kwargs)
¶
Raise an error if called.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
Any
|
... |
()
|
kwargs |
Any
|
... |
{}
|
Raises:
Type | Description |
---|---|
RuntimeError
|
Always. |
block_m_side_effects()
¶
Blocks functions that have side effects.
This function overrides the definition of m
so that we do not accidentally
try write a lot of files or create/move directories.
The pathlib.Path.mkdir function should only be blocked while developing
tests. It is a reminder that we haven't mocked the function yet. If we want
to get this reminder then add touch m/.m/pytest-ran
after the tests run
locally.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A dictionary with references to the original functions that were overridden in case these are needed. |
Source code in m/testing/testing.py
block_network_access()
¶
Blocks network access for all tests.
This function overrides the definition of socket
so that
we do not accidentally try to run tests that make network calls. If our tests
do not depend on other local services it is a good idea to call this before
any of our tests runs.
Otherwise we may want to modify this function to allow certain hosts to be called. (PRs welcomed).
Source code in m/testing/testing.py
mock(func_name)
¶
needs_mocking(func_name, *args, **kwargs)
¶
Raise an exception asking developer to mock a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func_name |
str
|
name of the function |
required |
args |
Any
|
... |
()
|
kwargs |
Any
|
... |
{}
|
Raises:
Type | Description |
---|---|
RuntimeError
|
Always. |