Repository: conda/conda

Issue:
`conda env remove --dry-run` actually deletes the env
## Current Behavior
Using the `--dry-run` flag doesn't do a dry-run at all.


### Steps to Reproduce
```
$ conda env list
# conda environments:
#
base                  *  /usr

$ conda create -n foo
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/eric/.conda/envs/foo



Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate foo
#
# To deactivate an active environment, use
#
#     $ conda deactivate

$ conda env list
# conda environments:
#
foo                      /home/eric/.conda/envs/foo
base                  *  /usr

~ $ conda env remove --dry-run -n foo

Remove all packages in environment /home/eric/.conda/envs/foo:

$ conda env list
# conda environments:
#
base                  *  /usr

$ 
```


## Expected Behavior
`--dry-run` is documented as `Only display what would have been done.`, but clearly that's not true :upside_down_face: 

The expected behaviour here is obviously that the environment is **not** removed :slightly_smiling_face: 


## Environment Information
<details open><summary><code>`conda info`</code></summary><p>

```
     active environment : None
            shell level : 0
       user config file : /home/eric/.condarc
 populated config files : /usr/share/conda/condarc.d/defaults.yaml
                          /home/eric/.condarc
          conda version : 4.8.2
    conda-build version : not installed
         python version : 3.8.5.final.0
       virtual packages : __glibc=2.31
       base environment : /usr  (read only)
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /var/cache/conda/pkgs
                          /home/eric/.conda/pkgs
       envs directories : /home/eric/.conda/envs
                          /usr/envs
               platform : linux-64
             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.8.5 Linux/5.8.6-201.fc32.x86_64 fedora/32 glibc/2.31
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>

```
==> /usr/share/conda/condarc.d/defaults.yaml <==
pkgs_dirs:
  - /var/cache/conda/pkgs
  - ~/.conda/pkgs

==> /home/eric/.condarc <==
channels:
  - conda-forge
  - defaults
```
</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->

```
EnvironmentLocationNotFound: Not a conda environment: /usr
```
(I expect that might also be a bug, conda shouldn't crash like that here.)
</p></details>



Discussion:

Resolving patch:
diff --git a/conda/cli/main_remove.py b/conda/cli/main_remove.py
--- a/conda/cli/main_remove.py
+++ b/conda/cli/main_remove.py
@@ -73,8 +73,9 @@ def execute(args, parser):
                 handle_txn(txn, prefix, args, False, True)
             except PackagesNotFoundError:
                 print("No packages found in %s. Continuing environment removal" % prefix)
-        rm_rf(prefix, clean_empty_parents=True)
-        unregister_env(prefix)
+        if not context.dry_run:
+            rm_rf(prefix, clean_empty_parents=True)
+            unregister_env(prefix)
 
         return
 


Test patch:
diff --git a/tests/conda_env/test_cli.py b/tests/conda_env/test_cli.py
--- a/tests/conda_env/test_cli.py
+++ b/tests/conda_env/test_cli.py
@@ -361,6 +361,14 @@ def test_update_env_no_action_json_output(self):
         output = json.loads(stdout)
         assert output["message"] == "All requested packages already installed."
 
+    def test_remove_dry_run(self):
+        # Test for GH-10231
+        create_env(environment_1)
+        run_env_command(Commands.ENV_CREATE, None)
+        env_name = "env-1"
+        run_env_command(Commands.ENV_REMOVE, env_name, "--dry-run")
+        self.assertTrue(env_is_created(env_name))
+
     def test_set_unset_env_vars(self):
         create_env(environment_1)
         run_env_command(Commands.ENV_CREATE, None)