Esempio n. 1
0
def tox_runtest(venv: VirtualEnv, redirect):
    """
	Create a temporary directory, symlink the test directory into it, and chdir into that directory.
	"""

    envconfig: TestenvConfig = venv.envconfig

    if envconfig.isolate_dirs:

        # venv.envconfig.setenv["COVERAGE_HOME"] = str(venv.path / "lib")
        # venv.envconfig.setenv["COVERAGE_HOME"] = envconfig.get_envsitepackagesdir()

        print(
            Style.BRIGHT(
                f"{envconfig.envname} run-test-pre: isolating test environment"
            ))

        source_dir = pathlib.Path.cwd()

        with TemporaryDirectory() as tmpdir:
            for directory in envconfig.isolate_dirs:
                if os.path.isabs(directory):
                    os.symlink(
                        directory,
                        pathlib.Path(tmpdir) /
                        os.path.relpath(directory, source_dir))
                else:
                    os.symlink(source_dir / directory,
                               pathlib.Path(tmpdir) / directory)

            venv.envconfig.changedir = py.path.local(tmpdir)
            venv.test(redirect=redirect)

            # copy .coverage from tmp dir back into root
            if (pathlib.Path(tmpdir) / ".coverage").is_file():
                shutil.copy2(
                    pathlib.Path(tmpdir) / ".coverage",
                    source_dir / ".coverage")
                fixup_coverage(old_base=envconfig.get_envsitepackagesdir(),
                               new_base=source_dir,
                               coverage_filename=source_dir / ".coverage")

        return True  # Return non-None to indicate plugin has completed

    return None
Esempio n. 2
0
def test_env_variables_added_to_pcall(tmpdir, mocksession, newconfig,
                                      monkeypatch):
    monkeypatch.delenv("PYTHONPATH", raising=False)
    pkg = tmpdir.ensure("package.tar.gz")
    monkeypatch.setenv("X123", "123")
    monkeypatch.setenv("YY", "456")
    config = newconfig(
        [],
        """
        [testenv:python]
        commands=python -V
        passenv = x123
        setenv =
            ENV_VAR = value
            PYTHONPATH = value
    """,
    )
    mocksession._clearmocks()

    venv = VirtualEnv(config.envconfigs["python"], session=mocksession)
    mocksession.installpkg(venv, pkg)
    venv.test()

    pcalls = mocksession._pcalls
    assert len(pcalls) == 2
    for x in pcalls:
        env = x.env
        assert env is not None
        assert "ENV_VAR" in env
        assert env["ENV_VAR"] == "value"
        assert env["VIRTUAL_ENV"] == str(venv.path)
        assert env["X123"] == "123"
        assert "PYTHONPATH" in env
        assert env["PYTHONPATH"] == "value"
    # all env variables are passed for installation
    assert pcalls[0].env["YY"] == "456"
    assert "YY" not in pcalls[1].env

    assert {"ENV_VAR", "VIRTUAL_ENV", "PYTHONHASHSEED", "X123",
            "PATH"}.issubset(pcalls[1].env)

    # setenv does not trigger PYTHONPATH warnings
    mocksession.report.not_expect("warning",
                                  "*Discarding $PYTHONPATH from environment*")
Esempio n. 3
0
def test_env_variables_added_to_pcall(tmpdir, mocksession, newconfig,
                                      monkeypatch):
    pkg = tmpdir.ensure("package.tar.gz")
    monkeypatch.setenv("X123", "123")
    monkeypatch.setenv("YY", "456")
    config = newconfig([], """
        [testenv:python]
        commands=python -V
        passenv = x123
        setenv =
            ENV_VAR = value
            PYTHONPATH = value
    """)
    mocksession._clearmocks()

    venv = VirtualEnv(config.envconfigs['python'], session=mocksession)
    mocksession.installpkg(venv, pkg)
    venv.test()

    l = mocksession._pcalls
    assert len(l) == 2
    for x in l:
        env = x.env
        assert env is not None
        assert 'ENV_VAR' in env
        assert env['ENV_VAR'] == 'value'
        assert env['VIRTUAL_ENV'] == str(venv.path)
        assert env['X123'] == "123"
        assert 'PYTHONPATH' in env
        assert env['PYTHONPATH'] == 'value'
    # all env variables are passed for installation
    assert l[0].env["YY"] == "456"
    assert "YY" not in l[1].env

    assert set(["ENV_VAR", "VIRTUAL_ENV", "PYTHONHASHSEED", "X123", "PATH"])\
        .issubset(l[1].env)

    # setenv does not trigger PYTHONPATH warnings
    mocksession.report.not_expect("warning",
                                  "*Discarding $PYTHONPATH from environment*")