Skip to content

Commit

Permalink
fix: fixed an issue where in-project venv wasn't listed
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer authored and neersighted committed Nov 6, 2022
1 parent b1e1e14 commit 3681f5b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/utils/env.py
Expand Up @@ -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()
):
Expand Down
26 changes: 26 additions & 0 deletions tests/console/commands/env/conftest.py
Expand Up @@ -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()
16 changes: 16 additions & 0 deletions tests/console/commands/env/test_list.py
Expand Up @@ -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

0 comments on commit 3681f5b

Please sign in to comment.