-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce test-specific environment variables
This commit adds two new functions to the integration tests utilities: get_test_env_value(varname: str, default_value: str) -> str get_test_env_value_int(varname: str, default_value: int) -> int This allows to set and get test-specific environment variables easily. Use case: Say we have an integration test, in which we want to assign a value for a variable WAIT_TIMEOUT externally from the environment, but we don't want to create a new fixture for it, as this value would be used only in this specific test. The expected environment variable name would be assembled from the prefix `TEST_`, test name (i.e. the directory name in which the test script is located) and the provided suffix, e.g. in test named `bluechi-generic-test`, the expected environment variable would be `TEST_BLUECHI_GENERIC_TEST_WAIT_TIMEOUT` Thus, using `WAIT_TIMEOUT = get_test_env_value_int("WAIT_TIMEOUT", 1000)` in the test named `bluechi-generic-test` will set WAIT_TIMEOUT the value of 1000, unless `TEST_BLUECHI_GENERIC_TEST_WAIT_TIMEOUT` environment variable is set with an integer value, which in that case would be assigned to `WAIT_TIMEOUT` Signed-off-by: Mark Kemel <[email protected]>
- Loading branch information
Showing
3 changed files
with
60 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,20 @@ TIMEOUT_COLLECT_TEST_RESULTS=20 | |
|
||
These can be set either in the `environment` section of the tmt plan or using the `-e` option when running tmt, e.g. `-eTIMEOUT_TEST_SETUP=40`. | ||
|
||
### Test-specific timeouts | ||
|
||
In addition to the mentioned above timeouts, there's a mechanism allowing to set values in specific tests via environment variables, which can be used to adjust test-specific timeouts via the environment. The expected environment variable name would be assembled from the prefix `TEST_`, test name and a provided suffix. | ||
|
||
**Example** | ||
Check failure on line 191 in tests/README.md GitHub Actions / MarkdownTrailing spaces
Check failure on line 191 in tests/README.md GitHub Actions / MarkdownEmphasis used instead of a heading
|
||
|
||
Given a test named `bluechi-generic-test` (i.e. the test script located in the directory `bluechi-generic-test`), which uses a timeout `WAIT_TIMEOUT`, defining it as follows: | ||
|
||
```python | ||
WAIT_TIMEOUT = get_test_env_value_int("WAIT_TIMEOUT", 1000) | ||
``` | ||
|
||
The variable would be assigned `WAIT_TIMEOUT = 1000`, unless environment variable `TEST_BLUECHI_GENERIC_TEST_WAIT_TIMEOUT` is set with an integer value, in which case this value would be passed to `WAIT_TIMEOUT`. | ||
|
||
## Developing integration tests | ||
|
||
### Code Style | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters