From 868b59f7fde18d4dcffc0b193182154cca4c6bf0 Mon Sep 17 00:00:00 2001 From: frostming Date: Wed, 18 Dec 2019 17:23:50 +0800 Subject: [PATCH] list .venv when it exists --- poetry/console/commands/env/list.py | 5 ++++- tests/console/commands/env/test_list.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/poetry/console/commands/env/list.py b/poetry/console/commands/env/list.py index 272a853b976..518d8a45820 100644 --- a/poetry/console/commands/env/list.py +++ b/poetry/console/commands/env/list.py @@ -15,8 +15,11 @@ def handle(self): manager = EnvManager(self.poetry) current_env = manager.get() + env_list = manager.list() + if current_env not in env_list: + env_list.insert(0, current_env) - for venv in manager.list(): + for venv in env_list: name = venv.path.name if self.option("full-path"): name = str(venv.path) diff --git a/tests/console/commands/env/test_list.py b/tests/console/commands/env/test_list.py index 1d79b8e57a7..7f9281485e5 100644 --- a/tests/console/commands/env/test_list.py +++ b/tests/console/commands/env/test_list.py @@ -1,3 +1,5 @@ +import os + import tomlkit from cleo.testers import CommandTester @@ -56,3 +58,17 @@ def test_activated(app, tmp_dir): ) assert expected == tester.io.fetch_output() + + +def test_in_project_venv(app, tmpdir): + os.environ.pop("VIRTUAL_ENV") + + (app.poetry.file.parent / ".venv").mkdir(exist_ok=True) + + command = app.find("env list") + tester = CommandTester(command) + tester.execute() + + expected = ".venv (Activated)\n" + + assert expected == tester.io.fetch_output()