• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Helper library to get environment variables for absltest helper binaries."""
2
3import os
4
5
6_INHERITED_ENV_KEYS = frozenset({
7    # This is needed to correctly use the Python interpreter determined by
8    # bazel.
9    'PATH',
10    # This is used by the random module on Windows to locate crypto
11    # libraries.
12    'SYSTEMROOT',
13})
14
15
16def inherited_env():
17  """Returns the environment variables that should be inherited from parent.
18
19  Reason why using an explicit list of environment variables instead of
20  inheriting all from parent: the absltest module itself interprets a list of
21  environment variables set by bazel, e.g. XML_OUTPUT_FILE,
22  TESTBRIDGE_TEST_ONLY. While testing absltest's own behavior, we should
23  remove them when invoking the helper subprocess. Using an explicit list is
24  safer.
25  """
26  env = {}
27  for key in _INHERITED_ENV_KEYS:
28    if key in os.environ:
29      env[key] = os.environ[key]
30  return env
31