Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/1998.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix processing of the ``VIRTUALENV_PYTHON`` environment variable
1 change: 1 addition & 0 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def add_parser_arguments(cls, parser):
"--python",
dest="python",
metavar="py",
type=str,
action="append",
default=[],
help="interpreter based on what to create environment (path/identifier) "
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/config/test_env_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from virtualenv.config.cli.parser import VirtualEnvOptions
from virtualenv.config.ini import IniConfig
from virtualenv.run import session_via_cli
from virtualenv.util.path import Path
Expand Down Expand Up @@ -31,6 +32,13 @@ def test_value_bad(monkeypatch, caplog, empty_conf):
assert "invalid literal" in caplog.messages[0]


def test_python_via_env_var(monkeypatch):
options = VirtualEnvOptions()
monkeypatch.setenv(str("VIRTUALENV_PYTHON"), str("python3"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to validate that python2,python3 works as expected too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extended the code to provide that functionality. Multi-value was split with newline so far, though it seems the only other multi-value field is extra-search-dir.

Let me know if you are happy with the approach taken or would prefer a different way to do this.

session_via_cli(["venv"], options=options)
assert options.python == ["python3"]


def test_extra_search_dir_via_env_var(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
value = "a{}0{}b{}c".format(os.linesep, os.linesep, os.pathsep)
Expand Down