conftest
This module is provided to help with testing.
The following external modules are expected to be available:
run_action_step(mocker, *, py_file, exit_code, env_vars, file_write_side_effect=None)
¶
Execute an action step in a test.
This function expects the inputs to the script to be provided via environment
variables of the form INPUT_[SOME_NAME]
. The script will write the outputs
to the file FAKE_GITHUB_OUTPUT.txt
. We can verify the contents of the file
by looking at the 3rd output from the function. This is a dictionary mapping
file names to contents. Please note that this testing function mocks
m.core.rw.write_file to obtain the file contents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mocker |
MockerFixture
|
A reference to the pytest |
required |
py_file |
str
|
The full path to the file that Github Actions will run. |
required |
exit_code |
int
|
The expected exit code of the action. |
required |
env_vars |
dict[str, str]
|
A dictionary of the environment variables that the action will receive. |
required |
file_write_side_effect |
Any | None
|
This can be provided if we need to modify the behavior of m.core.rw.write_file. This is useful if we want to test cases in which a file failed to write. |
None
|
Returns:
Type | Description |
---|---|
tuple[str, str, dict[str, str]]
|
The standard out, standard error, and files written by m.core.rw.write_file. |
Source code in m/testing/conftest.py
run_action_test_case(mocker, tcase)
¶
Execute an action step test case.
This is a commodity wrapper to help us run the action tests case. If we need more control over the assertions we can then copy and modify the implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mocker |
MockerFixture
|
A reference to the pytest |
required |
tcase |
ActionStepTestCase
|
The test case. |
required |