Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce test-specific environment variables #1014

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

mkemel
Copy link
Member

@mkemel mkemel commented Dec 17, 2024

This PR 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, without maintaining the unique naming for multiple environment variables.

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 passed to WAIT_TIMEOUT

Copy link
Member

@engelmi engelmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment, otherwise LGTM

Edit: Integration test fails due to a new selinux version. I triggered the image build and as soon as it completes, the pipeline should pass.

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]>
@coveralls
Copy link

coveralls commented Dec 17, 2024

Coverage Status

coverage: 80.974%. remained the same
when pulling 6200ee5 on mkemel:envvars
into de238cc on eclipse-bluechi:main.

Copy link
Member

@engelmi engelmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@engelmi engelmi merged commit 759f3a4 into eclipse-bluechi:main Dec 18, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants