question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Environment variable substitution should be attempted after each action

See original GitHub issue

I’m using tox-docker which exports some environment variables for me to use to connect to a container’s exposed port. I tried using setenv to construct a DSN from those environment variables so that the test suite will be able to know which container to connect to:

# ...
[setenv]
    redis: TEST_BROKER=redis://{env:REDIS_HOST}:{env:REDIS_6379_PORT}/0
    redis: TEST_BACKEND=redis://{env:REDIS_HOST}:{env:REDIS_6379_PORT}/1

This unfortunately fails in the following fashion:

tox -e 3.7-integration-redis -r
3.7-integration-redis create: /home/omer/Documents/Projects/celery/.tox/3.7-integration-redis
_________________________________________________________________________________________________ summary __________________________________________________________________________________________________
  3.7-integration-redis: commands succeeded
  congratulations :)
Traceback (most recent call last):
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 348, in get
    return self.resolved[name]
KeyError: 'TEST_BROKER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/omer/.local/share/virtualenvs/celery/bin/tox", line 10, in <module>
    sys.exit(cmdline())
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/session/__init__.py", line 42, in cmdline
    main(args)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/session/__init__.py", line 66, in main
    exit_code = session.runcommand()
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/session/__init__.py", line 190, in runcommand
    return self.subcommand_test()
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/session/__init__.py", line 218, in subcommand_test
    run_sequential(self.config, self.venv_dict)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/session/commands/run/sequential.py", line 9, in run_sequential
    if venv.setupenv():
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/venv.py", line 584, in setupenv
    status = self.update(action=action)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/venv.py", line 242, in update
    self.hook.tox_testenv_create(action=action, venv=self)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/pluggy/manager.py", line 68, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/pluggy/manager.py", line 62, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/venv.py", line 677, in tox_testenv_create
    redirect=reporter.verbosity() < reporter.Verbosity.DEBUG,
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/venv.py", line 543, in _pcall
    env = self._get_os_environ(is_test_command=is_test_command)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/venv.py", line 462, in _get_os_environ
    env.update(self.envconfig.setenv)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 364, in __getitem__
    x = self.get(name, self._DUMMY)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 358, in get
    self.resolved[name] = res = self.reader._replace(val)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 1517, in _replace
    replaced = Replacer(self, crossonly=crossonly).do_replace(value)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 1553, in do_replace
    expanded = substitute_once(value)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 1551, in substitute_once
    return self.RE_ITEM_REF.sub(self._replace_match, x)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 1589, in _replace_match
    return self._replace_env(match)
  File "/home/omer/.local/share/virtualenvs/celery/lib/python3.7/site-packages/tox/config/__init__.py", line 1610, in _replace_env
    raise tox.exception.MissingSubstitution(key)
tox.exception.MissingSubstitution: MissingSubstitution: REDIS_HOST

I’d like tox to defer variable substitution if it fails and retry it until the test commands are executed. If it failed before that, tox should fail as well.

This gives plugins the opportunity to export environment variables which we can use in latter stages.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gaborbernatcommented, May 21, 2019

In the meantime, as a workaround, I would propose you creating a plugin that does this 👍

0reactions
gaborbernatcommented, May 20, 2019

This will be duplicate of #1191 then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment variable substitution expects only one colon in ...
Environment variable substitution expects only one colon per string In curator config file I can define only one colon if there is a ......
Read more >
How to use variable substitution in Frontend js applications ...
I am working on a React app using create-react-app and I'm trying to find an easy way to substitute variables (eg. API Address)...
Read more >
Variable substitution - execline - skarnet.org
A substitution command takes a key, i.e. a string (which can contain any character but $, { and }, although it is recommended...
Read more >
Environment variables in Compose | Docker Documentation
Substitute environment variables in Compose files. If you have multiple environment variables, you can substitute them by adding them to a default environment...
Read more >
How to use a YAML file or environment variables to populate ...
Environment variable substitution is supported in both the great_expectations.yml and config variables config_variables.yml config file. If using a YAML file, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found