Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test__create_venv_options fails without conda #793

Closed
mtelka opened this issue Mar 4, 2024 · 5 comments · Fixed by #794
Closed

test__create_venv_options fails without conda #793

mtelka opened this issue Mar 4, 2024 · 5 comments · Fixed by #794
Labels

Comments

@mtelka
Copy link

mtelka commented Mar 4, 2024

Current Behavior

I'm running tests for nox and I found that TestSessionRunner.test__create_venv_options[nox.virtualenv.CondaEnv.create-conda-CondaEnv] fails because I've no conda installed:

_ TestSessionRunner.test__create_venv_options[nox.virtualenv.CondaEnv.create-conda-CondaEnv] _

self = <test_sessions.TestSessionRunner object at 0x7fffad2f92e0>
create_method = 'nox.virtualenv.CondaEnv.create', venv_backend = 'conda'
expected_backend = <class 'nox.virtualenv.CondaEnv'>

    @pytest.mark.parametrize(
        "create_method,venv_backend,expected_backend",
        [
            ("nox.virtualenv.VirtualEnv.create", None, nox.virtualenv.VirtualEnv),
            (
                "nox.virtualenv.VirtualEnv.create",
                "virtualenv",
                nox.virtualenv.VirtualEnv,
            ),
            ("nox.virtualenv.VirtualEnv.create", "venv", nox.virtualenv.VirtualEnv),
            ("nox.virtualenv.CondaEnv.create", "conda", nox.virtualenv.CondaEnv),
        ],
    )
    def test__create_venv_options(self, create_method, venv_backend, expected_backend):
        runner = self.make_runner()
        runner.func.python = "coolpython"
        runner.func.reuse_venv = True
        runner.func.venv_backend = venv_backend

        with mock.patch(create_method, autospec=True) as create:
>           runner._create_venv()

$(BUILD_DIR)/tests/test_sessions.py:959:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <nox.sessions.SessionRunner object at 0x7fffad054070>

    def _create_venv(self) -> None:
        reuse_existing = self.reuse_existing_venv()

        backends = (
            self.global_config.force_venv_backend
            or self.func.venv_backend
            or self.global_config.default_venv_backend
            or "virtualenv"
        ).split("|")

        # Support fallback backends
        for bk in backends:
            if bk not in nox.virtualenv.ALL_VENVS:
                msg = f"Expected venv_backend one of {list(nox.virtualenv.ALL_VENVS)!r}, but got {bk!r}."
                raise ValueError(msg)

        for bk in backends[:-1]:
            if bk not in nox.virtualenv.OPTIONAL_VENVS:
                msg = f"Only optional backends ({list(nox.virtualenv.OPTIONAL_VENVS)!r}) may have a fallback, {bk!r} is not optional."
                raise ValueError(msg)

        for bk in backends:
            if nox.virtualenv.OPTIONAL_VENVS.get(bk, True):
                backend = bk
                break
        else:
            msg = f"No backends present, looked for {backends!r}."
>           raise ValueError(msg)
E           ValueError: No backends present, looked for ['conda'].
$(BUILD_DIR)/nox/sessions.py:791: ValueError

Expected Behavior

All tests pass even without conda.

Steps To Reproduce

Run nox tests without conda installed.

Environment

- OS: OpenIndiana
- Python: 3.9.18
- Nox: 2024.3.2

Anything else?

No response

@mtelka mtelka added the bug label Mar 4, 2024
@cjolowicz
Copy link
Collaborator

Thanks for reporting! I could reproduce.

Would something like this work?

            pytest.param("nox.virtualenv.CondaEnv.create", "conda", nox.virtualenv.CondaEnv, marks=has_conda),

The has_conda marker is defined in test_virtualenv.py.

@mtelka
Copy link
Author

mtelka commented Mar 5, 2024

/usr/lib/python3.9/ast.py:50: in parse
    return compile(source, filename, mode, flags,
E     File "$(BUILD_DIR)/tests/test_sessions.py", line 949
E       ("nox.virtualenv.CondaEnv.create", "conda", nox.virtualenv.CondaEnv, marks=has_conda),
E                                                                                 ^
E   SyntaxError: invalid syntax

@mtelka
Copy link
Author

mtelka commented Mar 5, 2024

Above tested with this patch:

--- nox-2024.3.2/tests/test_sessions.py.orig
+++ nox-2024.3.2/tests/test_sessions.py
@@ -946,7 +946,7 @@
                 nox.virtualenv.VirtualEnv,
             ),
             ("nox.virtualenv.VirtualEnv.create", "venv", nox.virtualenv.VirtualEnv),
-            ("nox.virtualenv.CondaEnv.create", "conda", nox.virtualenv.CondaEnv),
+            ("nox.virtualenv.CondaEnv.create", "conda", nox.virtualenv.CondaEnv, marks=has_conda),
         ],
     )
     def test__create_venv_options(self, create_method, venv_backend, expected_backend):

@mtelka
Copy link
Author

mtelka commented Mar 5, 2024

I looked at #794 and I had to use it differently. Sorry for mess.

@mtelka
Copy link
Author

mtelka commented Mar 5, 2024

I tested with patch from #794 and now the test is properly skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants