def _getenv()

in pylib/mercurial-support/run-tests.py [0:0]


    def _getenv(self):
        """Obtain environment variables to use during test execution."""

        def defineport(i):
            offset = '' if i == 0 else '%s' % i
            env["HGPORT%s" % offset] = '%s' % (self._startport + i)

        env = os.environ.copy()
        env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or ''
        # TRACKING MOZ - add ERR_FILE and set 9 ports
        env['HGEMITWARNINGS'] = '1'
        env['TESTTMP'] = _strpath(self._testtmp)
        env['TESTNAME'] = self.name
        env['HOME'] = _strpath(self._testtmp)
        # This number should match portneeded in _getport
        for port in xrange(9):
            # This list should be parallel to _portmap in _getreplacements
            defineport(port)
        env["HGRCPATH"] = _strpath(os.path.join(self._threadtmp, b'.hgrc'))
        env["DAEMON_PIDS"] = _strpath(
            os.path.join(self._threadtmp, b'daemon.pids')
        )
        env["HGEDITOR"] = (
            '"' + sysexecutable + '"' + ' -c "import sys; sys.exit(0)"'
        )
        env["HGUSER"] = "test"
        env["HGENCODING"] = "ascii"
        env["HGENCODINGMODE"] = "strict"
        env["HGHOSTNAME"] = "test-hostname"
        env['HGIPV6'] = str(int(self._useipv6))
        env["ERR_FILE"] = self.errpath
        # See contrib/catapipe.py for how to use this functionality.
        if 'HGTESTCATAPULTSERVERPIPE' not in env:
            # If we don't have HGTESTCATAPULTSERVERPIPE explicitly set, pull the
            # non-test one in as a default, otherwise set to devnull
            env['HGTESTCATAPULTSERVERPIPE'] = env.get(
                'HGCATAPULTSERVERPIPE', os.devnull
            )

        extraextensions = []
        for opt in self._extraconfigopts:
            section, key = opt.encode('utf-8').split(b'.', 1)
            if section != 'extensions':
                continue
            name = key.split(b'=', 1)[0]
            extraextensions.append(name)

        if extraextensions:
            env['HGTESTEXTRAEXTENSIONS'] = b' '.join(extraextensions)

        # LOCALIP could be ::1 or 127.0.0.1. Useful for tests that require raw
        # IP addresses.
        env['LOCALIP'] = _strpath(self._localip())

        # TRACKING MOZ - set LOCALHOST for cross-platform localhost naming
        env['LOCALHOST'] = _strpath(self._localhostname())

        # This has the same effect as Py_LegacyWindowsStdioFlag in exewrapper.c,
        # but this is needed for testing python instances like dummyssh,
        # dummysmtpd.py, and dumbhttp.py.
        if PYTHON3 and os.name == 'nt':
            env['PYTHONLEGACYWINDOWSSTDIO'] = '1'

        # Modified HOME in test environment can confuse Rust tools. So set
        # CARGO_HOME and RUSTUP_HOME automatically if a Rust toolchain is
        # present and these variables aren't already defined.
        cargo_home_path = os.path.expanduser('~/.cargo')
        rustup_home_path = os.path.expanduser('~/.rustup')

        if os.path.exists(cargo_home_path) and b'CARGO_HOME' not in osenvironb:
            env['CARGO_HOME'] = cargo_home_path
        if (
            os.path.exists(rustup_home_path)
            and b'RUSTUP_HOME' not in osenvironb
        ):
            env['RUSTUP_HOME'] = rustup_home_path

        # Reset some environment variables to well-known values so that
        # the tests produce repeatable output.
        env['LANG'] = env['LC_ALL'] = env['LANGUAGE'] = 'C'
        env['TZ'] = 'GMT'
        env["EMAIL"] = "Foo Bar <foo.bar@example.com>"
        env['COLUMNS'] = '80'
        env['TERM'] = 'xterm'

        dropped = [
            'CDPATH',
            'CHGDEBUG',
            'EDITOR',
            'GREP_OPTIONS',
            'HG',
            'HGMERGE',
            'HGPLAIN',
            'HGPLAINEXCEPT',
            'HGPROF',
            'http_proxy',
            'no_proxy',
            'NO_PROXY',
            'PAGER',
            'VISUAL',
        ]

        for k in dropped:
            if k in env:
                del env[k]

        # unset env related to hooks
        for k in list(env):
            if k.startswith('HG_'):
                del env[k]

        if self._usechg:
            env['CHGSOCKNAME'] = os.path.join(self._chgsockdir, b'server')

        return env