diff --git a/poetry/utils/env.py b/poetry/utils/env.py index e55e0ee83c1..0c326880ba1 100644 --- a/poetry/utils/env.py +++ b/poetry/utils/env.py @@ -372,11 +372,20 @@ def list(self, name=None): # type: (Optional[str]) -> List[VirtualEnv] else: venv_path = Path(venv_path) - return [ + env_list = [ VirtualEnv(Path(p)) for p in sorted(venv_path.glob("{}-py*".format(venv_name))) ] + venv = self._poetry.file.parent / ".venv" + if ( + self._poetry.config.get("virtualenvs.in-project") + and venv.exists() + and venv.is_dir() + ): + env_list.insert(0, VirtualEnv(venv)) + return env_list + def remove(self, python): # type: (str) -> Env venv_path = self._poetry.config.get("virtualenvs.path") if venv_path is None: diff --git a/tests/console/commands/env/test_list.py b/tests/console/commands/env/test_list.py index e9112449307..e2946373b6a 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 @@ -58,3 +60,19 @@ def test_activated(app, tmp_dir): ) assert expected == tester.io.fetch_output() + + +def test_in_project_venv(app, tmpdir): + os.environ.pop("VIRTUAL_ENV", None) + app.poetry.config.merge({"virtualenvs": {"in-project": True}}) + + (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() + (app.poetry.file.parent / ".venv").rmdir()