Repository: tox-dev/tox

Issue:
tox4: list_dependencies_command support
👍🏻 

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/tox-dev/tox/pull/1887?src=pr&el=h1) Report
> Merging [#1887](https://codecov.io/gh/tox-dev/tox/pull/1887?src=pr&el=desc) (58f0c0e) into [rewrite](https://codecov.io/gh/tox-dev/tox/commit/6d9b2dff59f220f6b3bae1fedcb888fd113bf269?el=desc) (6d9b2df) will **increase** coverage by `0.18%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/tox-dev/tox/pull/1887/graphs/tree.svg?width=650&height=150&src=pr&token=DYodAwDCZ5)](https://codecov.io/gh/tox-dev/tox/pull/1887?src=pr&el=tree)

```diff
@@             Coverage Diff              @@
##           rewrite     #1887      +/-   ##
============================================
+ Coverage    99.81%   100.00%   +0.18%     
============================================
  Files          135       133       -2     
  Lines         7487      7342     -145     
  Branches       748       722      -26     
============================================
- Hits          7473      7342     -131     
+ Misses           3         0       -3     
+ Partials        11         0      -11     
```

| Flag | Coverage Δ | |
|---|---|---|
| tests | `100.00% <100.00%> (+0.18%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/tox-dev/tox/pull/1887?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/tox/tox\_env/python/virtual\_env/api.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC90b3hfZW52L3B5dGhvbi92aXJ0dWFsX2Vudi9hcGkucHk=) | `100.00% <100.00%> (ø)` | |
| [.../tox\_env/python/virtual\_env/test\_virtualenv\_api.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-dGVzdHMvdG94X2Vudi9weXRob24vdmlydHVhbF9lbnYvdGVzdF92aXJ0dWFsZW52X2FwaS5weQ==) | `100.00% <100.00%> (ø)` | |
| [src/tox/tox\_env/api.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC90b3hfZW52L2FwaS5weQ==) | `100.00% <0.00%> (ø)` | |
| [src/tox/execute/request.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC9leGVjdXRlL3JlcXVlc3QucHk=) | `100.00% <0.00%> (ø)` | |
| [...ecute/local\_sub\_process/read\_via\_thread\_windows.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC9leGVjdXRlL2xvY2FsX3N1Yl9wcm9jZXNzL3JlYWRfdmlhX3RocmVhZF93aW5kb3dzLnB5) | | |
| [tests/conftest.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-dGVzdHMvY29uZnRlc3QucHk=) | | |
| [src/tox/tox\_env/python/api.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC90b3hfZW52L3B5dGhvbi9hcGkucHk=) | `100.00% <0.00%> (+0.68%)` | :arrow_up: |
| [src/tox/config/loader/str\_convert.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC9jb25maWcvbG9hZGVyL3N0cl9jb252ZXJ0LnB5) | `100.00% <0.00%> (+1.47%)` | :arrow_up: |
| [src/tox/util/spinner.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC91dGlsL3NwaW5uZXIucHk=) | `100.00% <0.00%> (+2.30%)` | :arrow_up: |
| [src/tox/execute/local\_sub\_process/\_\_init\_\_.py](https://codecov.io/gh/tox-dev/tox/pull/1887/diff?src=pr&el=tree#diff-c3JjL3RveC9leGVjdXRlL2xvY2FsX3N1Yl9wcm9jZXNzL19faW5pdF9fLnB5) | `100.00% <0.00%> (+4.37%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tox-dev/tox/pull/1887?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tox-dev/tox/pull/1887?src=pr&el=footer). Last update [6d9b2df...58f0c0e](https://codecov.io/gh/tox-dev/tox/pull/1887?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/docs/changelog/1842.feature.rst b/docs/changelog/1842.feature.rst
new file mode 100644
index 00000000..e12296f6
--- /dev/null
+++ b/docs/changelog/1842.feature.rst
@@ -0,0 +1,2 @@
+Add support for the ``list_dependencies_command`` settings in the virtual env test environments - by
+:user:`gaborbernat`.
diff --git a/src/tox/tox_env/python/virtual_env/api.py b/src/tox/tox_env/python/virtual_env/api.py
index ac0902cf..e1a75057 100644
--- a/src/tox/tox_env/python/virtual_env/api.py
+++ b/src/tox/tox_env/python/virtual_env/api.py
@@ -67,7 +67,6 @@ class VirtualEnv(Python, ABC):
             default=False,
             desc="install the latest available pre-release (alpha/beta/rc) of dependencies without a specified version",
         )
-
         self.conf.add_config(
             keys=["install_command"],
             of_type=Command,
@@ -75,6 +74,12 @@ class VirtualEnv(Python, ABC):
             post_process=self.post_process_install_command,
             desc="install the latest available pre-release (alpha/beta/rc) of dependencies without a specified version",
         )
+        self.conf.add_config(
+            keys=["list_dependencies_command"],
+            of_type=Command,
+            default=Command(["python", "-m", "pip", "freeze", "--all"]),
+            desc="install the latest available pre-release (alpha/beta/rc) of dependencies without a specified version",
+        )
 
     def post_process_install_command(self, cmd: Command) -> Command:
         install_command = cmd.args
@@ -218,9 +223,9 @@ class VirtualEnv(Python, ABC):
         )
 
     def get_installed_packages(self) -> List[str]:
-        list_command = [self.creator.exe, "-I", "-m", "pip", "freeze", "--all"]
+        cmd: Command = self.conf["list_dependencies_command"]
         result = self.execute(
-            cmd=list_command,
+            cmd=cmd.args,
             stdin=StdinSource.OFF,
             run_id="freeze",
             show=self.options.verbosity > DEFAULT_VERBOSITY,


Test patch:
diff --git a/tests/tox_env/python/virtual_env/test_virtualenv_api.py b/tests/tox_env/python/virtual_env/test_virtualenv_api.py
index 0a406596..1fe07ebc 100644
--- a/tests/tox_env/python/virtual_env/test_virtualenv_api.py
+++ b/tests/tox_env/python/virtual_env/test_virtualenv_api.py
@@ -145,3 +145,13 @@ def test_install_command_no_packages(
     request: ExecuteRequest = execute_calls.call_args[0][3]
     found_cmd = request.cmd
     assert found_cmd[:-1] == ["python", "-m", "pip", "install", "-i", disable_pip_pypi_access[0], "--pre", "-r"]
+
+
+def test_list_dependencies_command(tox_project: ToxProjectCreator, monkeypatch: MonkeyPatch) -> None:
+    install_cmd = "python -m pip freeze"
+    proj = tox_project({"tox.ini": f"[testenv]\npackage=skip\nlist_dependencies_command={install_cmd}"})
+    execute_calls = proj.patch_execute(lambda r: 0 if "install" in r.run_id else None)
+    result = proj.run("r", "--result-json", str(proj.path / "out.json"))
+    result.assert_success()
+    request: ExecuteRequest = execute_calls.call_args[0][3]
+    assert request.cmd == ["python", "-m", "pip", "freeze"]