From 3681f5b7a81d8ef2a159791b6a633bb5b3bc2a48 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sun, 6 Nov 2022 08:34:28 +0100 Subject: [PATCH] fix: fixed an issue where in-project venv wasn't listed --- src/poetry/utils/env.py | 2 +- tests/console/commands/env/conftest.py | 26 +++++++++++++++++++++++++ tests/console/commands/env/test_list.py | 16 +++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 0a985ceef0d..74a5de8aa76 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -734,7 +734,7 @@ def list(self, name: str | None = None) -> list[VirtualEnv]: venv = self._poetry.file.parent / ".venv" if ( - self._poetry.config.get("virtualenvs.in-project") + self._poetry.config.get("virtualenvs.in-project") is not False and venv.exists() and venv.is_dir() ): diff --git a/tests/console/commands/env/conftest.py b/tests/console/commands/env/conftest.py index 32827c33e7a..832efe5e5cc 100644 --- a/tests/console/commands/env/conftest.py +++ b/tests/console/commands/env/conftest.py @@ -66,3 +66,29 @@ def venvs_in_project_dir(app: PoetryTestApplication) -> Iterator[Path]: yield venv_dir finally: venv_dir.rmdir() + + +@pytest.fixture +def venvs_in_project_dir_none(app: PoetryTestApplication) -> Iterator[Path]: + os.environ.pop("VIRTUAL_ENV", None) + venv_dir = app.poetry.file.parent.joinpath(".venv") + venv_dir.mkdir(exist_ok=True) + app.poetry.config.merge({"virtualenvs": {"in-project": None}}) + + try: + yield venv_dir + finally: + venv_dir.rmdir() + + +@pytest.fixture +def venvs_in_project_dir_false(app: PoetryTestApplication) -> Iterator[Path]: + os.environ.pop("VIRTUAL_ENV", None) + venv_dir = app.poetry.file.parent.joinpath(".venv") + venv_dir.mkdir(exist_ok=True) + app.poetry.config.merge({"virtualenvs": {"in-project": False}}) + + try: + yield venv_dir + finally: + venv_dir.rmdir() diff --git a/tests/console/commands/env/test_list.py b/tests/console/commands/env/test_list.py index 2f284470bbd..4a69dac0c3f 100644 --- a/tests/console/commands/env/test_list.py +++ b/tests/console/commands/env/test_list.py @@ -60,3 +60,19 @@ def test_in_project_venv(tester: CommandTester, venvs_in_project_dir: list[str]) tester.execute() expected = ".venv (Activated)\n" assert tester.io.fetch_output() == expected + + +def test_in_project_venv_no_explicit_config( + tester: CommandTester, venvs_in_project_dir_none: list[str] +): + tester.execute() + expected = ".venv (Activated)\n" + assert tester.io.fetch_output() == expected + + +def test_in_project_venv_is_false( + tester: CommandTester, venvs_in_project_dir_false: list[str] +): + tester.execute() + expected = "" + assert tester.io.fetch_output() == expected