Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: in-project venv not recognized when not requested #6979

Merged
merged 1 commit into from Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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