Repository: tox-dev/tox-conda

Issue:
Behavior for relative paths in `environment.yml` changed.
Hi,

thanks for the package! Unfortunately, the new release broke my setup. The folder structure looks roughly like this

```
- docs
  - rtd_environment.yml
- tox.ini
- src
  - package
```

I use `rtd_environment.yml` in my `tox.ini` to create the environment for the documentation. The env file contains a pip section to install the package from the repo.

```
...
- dependencies:
  ...
  - pip:
    - -e ../
```

With v0.10.0 the pip command fails. It says the directory does not contain a `setup.py` or `pyproject.toml`
. Everything works with v0.9.2.

The issue can be reproduced in this repo (https://github.com/pytask-dev/pytask/tree/e3c1a4cf6935a0c5cf14267acf9b5597261b3a7f) by typing `tox -e sphinx`.

Discussion:
tobiasraabe: Hi @AdrianFreundQC, it does fix the issue 🎉. Thanks a lot!

Patch:
diff --git a/tox_conda/plugin.py b/tox_conda/plugin.py
index 8cfa2e4..d669718 100644
--- a/tox_conda/plugin.py
+++ b/tox_conda/plugin.py
@@ -160,14 +160,17 @@ def tox_testenv_create(venv, action):
     python = get_py_version(venv.envconfig, action)
 
     if venv.envconfig.conda_env is not None:
+        env_path = Path(venv.envconfig.conda_env)
         # conda env create does not have a --channel argument nor does it take
         # dependencies specifications (e.g., python=3.8). These must all be specified
         # in the conda-env.yml file
         yaml = YAML()
-        env_file = yaml.load(Path(venv.envconfig.conda_env))
+        env_file = yaml.load(env_path)
         env_file["dependencies"].append(python)
 
-        with tempfile.NamedTemporaryFile(suffix=".yaml") as tmp_env:
+        with tempfile.NamedTemporaryFile(
+            dir=env_path.parent, prefix="tox_conda_tmp", suffix=".yaml"
+        ) as tmp_env:
             yaml.dump(env_file, tmp_env)
 
             args = [


Test patch:
diff --git a/tests/test_conda_env.py b/tests/test_conda_env.py
index 6ef26ef..4435c15 100644
--- a/tests/test_conda_env.py
+++ b/tests/test_conda_env.py
@@ -281,6 +281,8 @@ def test_conda_env(tmpdir, newconfig, mocksession):
         with mocksession.newaction(venv.name, "getenv") as action:
             tox_testenv_create(action=action, venv=venv)
 
+    mock_file.assert_called_with(dir=tmpdir, prefix="tox_conda_tmp", suffix=".yaml")
+
     pcalls = mocksession._pcalls
     assert len(pcalls) >= 1
     call = pcalls[-1]
@@ -291,8 +293,6 @@ def test_conda_env(tmpdir, newconfig, mocksession):
     assert call.args[5].startswith("--file")
     assert cmd[6] == str(mock_file().name)
 
-    mock_file.assert_any_call(suffix=".yaml")
-
     yaml = YAML()
     tmp_env = yaml.load(mock_open_to_string(mock_file))
     assert tmp_env["dependencies"][-1].startswith("python=")
@@ -338,6 +338,8 @@ def test_conda_env_and_spec(tmpdir, newconfig, mocksession):
         with mocksession.newaction(venv.name, "getenv") as action:
             tox_testenv_create(action=action, venv=venv)
 
+    mock_file.assert_called_with(dir=tmpdir, prefix="tox_conda_tmp", suffix=".yaml")
+
     pcalls = mocksession._pcalls
     assert len(pcalls) >= 1
     call = pcalls[-1]
@@ -348,8 +350,6 @@ def test_conda_env_and_spec(tmpdir, newconfig, mocksession):
     assert call.args[5].startswith("--file")
     assert cmd[6] == str(mock_file().name)
 
-    mock_file.assert_any_call(suffix=".yaml")
-
     yaml = YAML()
     tmp_env = yaml.load(mock_open_to_string(mock_file))
     assert tmp_env["dependencies"][-1].startswith("python=")