Skip to content

Commit def1ee8

Browse files
authored
fix: fixed an issue where in-project venv wasn't listed
1 parent b1e1e14 commit def1ee8

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/poetry/utils/env.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def list(self, name: str | None = None) -> list[VirtualEnv]:
734734

735735
venv = self._poetry.file.parent / ".venv"
736736
if (
737-
self._poetry.config.get("virtualenvs.in-project")
737+
self._poetry.config.get("virtualenvs.in-project") is not False
738738
and venv.exists()
739739
and venv.is_dir()
740740
):

tests/console/commands/env/conftest.py

+26
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,29 @@ def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]:
6666
yield venv_dir
6767
finally:
6868
venv_dir.rmdir()
69+
70+
71+
@pytest.fixture
72+
def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]:
73+
os.environ.pop("VIRTUAL_ENV", None)
74+
venv_dir = app.poetry.file.parent.joinpath(".venv")
75+
venv_dir.mkdir(exist_ok=True)
76+
app.poetry.config.merge({"virtualenvs": {"in-project": None}})
77+
78+
try:
79+
yield venv_dir
80+
finally:
81+
venv_dir.rmdir()
82+
83+
84+
@pytest.fixture
85+
def venvs_in_project_dir_false(app: PoetryTestApplication) -> Iterator[Path]:
86+
os.environ.pop("VIRTUAL_ENV", None)
87+
venv_dir = app.poetry.file.parent.joinpath(".venv")
88+
venv_dir.mkdir(exist_ok=True)
89+
app.poetry.config.merge({"virtualenvs": {"in-project": False}})
90+
91+
try:
92+
yield venv_dir
93+
finally:
94+
venv_dir.rmdir()

tests/console/commands/env/test_list.py

+16
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,19 @@ def test_in_project_venv(tester: CommandTester, venvs_in_project_dir: list[str])
6060
tester.execute()
6161
expected = ".venv (Activated)\n"
6262
assert tester.io.fetch_output() == expected
63+
64+
65+
def test_in_project_venv_no_explicit_config(
66+
tester: CommandTester, venvs_in_project_dir_none: list[str]
67+
):
68+
tester.execute()
69+
expected = ".venv (Activated)\n"
70+
assert tester.io.fetch_output() == expected
71+
72+
73+
def test_in_project_venv_is_false(
74+
tester: CommandTester, venvs_in_project_dir_false: list[str]
75+
):
76+
tester.execute()
77+
expected = ""
78+
assert tester.io.fetch_output() == expected

0 commit comments

Comments
 (0)