Skip to content

Default values for environment variables #3382

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

Closed
VVasyaev opened this issue Nov 21, 2019 · 7 comments
Closed

Default values for environment variables #3382

VVasyaev opened this issue Nov 21, 2019 · 7 comments
Labels
Milestone

Comments

@VVasyaev
Copy link
Contributor

VVasyaev commented Nov 21, 2019

Hello!

All of my projects uses a bunch of env vars for configuration.

Sometimes these needs to have some defaults.

As a workaround i made a keyword with OperatingSystem.Get Environment Variable and try to load the env var there or put default. The cons of it is -- any keyword, which uses my env var's value need to get that 'loading' keyword running. It seems to be silly.

I'd like to have some default value feature in the %{} structure.

For example:

*** Variables ***
${var_uses_everywhere}    %{MY_ENV_VAR:default_value_if_missing}

or
%{MY_ENV_VAR:-default_value_if_missing}
to mimic bash ${a:-b} structure.

It seems not so hard to implement such behavior.

@pekkaklarck
Copy link
Member

Although it shouldn't be overly complicated to make sure all needed environment variables are set before execution, I can see this could sometimes be useful and make configuration easier. I got a feeling that : is actually allowed in environment variable name (shell may not like it), but = shouldn't be so %{VAR=default} would be a bit better.

Are you interested to implement this and provide a PR? I can help if needed.

@VVasyaev
Copy link
Contributor Author

One of my project consists of lot of services, each of them running the same RF-tests repository (all of them have common keywords, resources, libraries, etc.) with different tags which helps to start the correct tests. The main issue is -- each service can be started on different envs and have lot of configuration differences (here are several dev teams creating these services) -- so defaults is very important for me.

As for PR -- i would like to try! Anyway, you can always say what i did wrong in PR. However, i didn't contribute in RF code earlier so if you have some suggestions -- i'd appreciate!

@VVasyaev
Copy link
Contributor Author

@pekkaklarck pls see #3384 PR
i'd also added two test-cases

@pekkaklarck
Copy link
Member

Yeah, there definitely are use cases where this would help. Robot's own acceptance test runner sets a Python interpreter and OS specific TEMPDIR environment variable, and sometimes when running tests directly, without the runner, you need to explicitly set it as well. We could change the current usages of %{TEMPDIR} to %{TEMPDIR=${TEMPDIR}} to use the OS default temporary directory in these cases.

Implementing this would actually be pretty simple. The code related to finding environment variables is pretty simple and editing it to split the possible default value from the name and returning it if there's no match shouldn't be hard either. You'd need to also create some acceptance tests and update docs.

To get started, see the contributing guidelines. If you have questions, don't hesitate to ask here or on the #devel channel in our Slack.

@pekkaklarck
Copy link
Member

Didn't see you earlier comment or the PR when I wrote my previous comment. Good start with the PR but some changes are needed.

@VVasyaev
Copy link
Contributor Author

@pekkaklarck pls review #3384 one more time...

@pekkaklarck pekkaklarck added acknowledge To be acknowledged in release notes beta 1 labels Nov 25, 2019
@pekkaklarck pekkaklarck added this to the v3.2 milestone Nov 25, 2019
@pekkaklarck
Copy link
Member

This was implemented by the great PR #3384 by @VVasyaev!

@pekkaklarck pekkaklarck changed the title Default values for environment variables. Default values for environment variables Jan 3, 2020
ngoan1608 pushed a commit to ngoan1608/robotframework that referenced this issue Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants