How to use the nox.sessions.SessionRunner function in nox

To help you get started, we’ve selected a few nox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github theacodes / nox / tests / test_sessions.py View on Github external
def make_runner(self):
        func = mock.Mock()
        func.python = None
        func.venv_backend = None
        func.reuse_venv = False
        runner = nox.sessions.SessionRunner(
            name="test",
            signatures=["test(1, 2)"],
            func=func,
            global_config=_options.options.namespace(
                noxfile=os.path.join(os.getcwd(), "noxfile.py"),
                envdir="envdir",
                posargs=mock.sentinel.posargs,
                reuse_existing_virtualenvs=False,
                error_on_missing_interpreters=False,
            ),
            manifest=mock.create_autospec(nox.manifest.Manifest),
        )
        return runner
github theacodes / nox / tests / test_sessions.py View on Github external
def test_install(self):
        runner = nox.sessions.SessionRunner(
            name="test",
            signatures=["test"],
            func=mock.sentinel.func,
            global_config=_options.options.namespace(posargs=mock.sentinel.posargs),
            manifest=mock.create_autospec(nox.manifest.Manifest),
        )
        runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
        runner.venv.env = {}

        class SessionNoSlots(nox.sessions.Session):
            pass

        session = SessionNoSlots(runner=runner)

        with mock.patch.object(session, "_run", autospec=True) as run:
            session.install("requests", "urllib3")
github theacodes / nox / tests / test_sessions.py View on Github external
def test_install_non_default_kwargs(self):
        runner = nox.sessions.SessionRunner(
            name="test",
            signatures=["test"],
            func=mock.sentinel.func,
            global_config=_options.options.namespace(posargs=mock.sentinel.posargs),
            manifest=mock.create_autospec(nox.manifest.Manifest),
        )
        runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
        runner.venv.env = {}

        class SessionNoSlots(nox.sessions.Session):
            pass

        session = SessionNoSlots(runner=runner)

        with mock.patch.object(session, "_run", autospec=True) as run:
            session.install("requests", "urllib3", silent=False)
github theacodes / nox / tests / test_sessions.py View on Github external
def make_session_and_runner(self):
        func = mock.Mock(spec=["python"], python="3.7")
        runner = nox.sessions.SessionRunner(
            name="test",
            signatures=["test"],
            func=func,
            global_config=_options.options.namespace(
                posargs=mock.sentinel.posargs,
                error_on_external_run=False,
                install_only=False,
            ),
            manifest=mock.create_autospec(nox.manifest.Manifest),
        )
        runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
        runner.venv.env = {}
        runner.venv.bin = "/no/bin/for/you"
        return nox.sessions.Session(runner=runner), runner
github theacodes / nox / tests / test_sessions.py View on Github external
def test_conda_install(self):
        runner = nox.sessions.SessionRunner(
            name="test",
            signatures=["test"],
            func=mock.sentinel.func,
            global_config=_options.options.namespace(posargs=mock.sentinel.posargs),
            manifest=mock.create_autospec(nox.manifest.Manifest),
        )
        runner.venv = mock.create_autospec(nox.virtualenv.CondaEnv)
        runner.venv.location = "/path/to/conda/env"
        runner.venv.env = {}

        class SessionNoSlots(nox.sessions.Session):
            pass

        session = SessionNoSlots(runner=runner)

        with mock.patch.object(session, "_run", autospec=True) as run:
github theacodes / nox / nox / manifest.py View on Github external
single_func.python = python
                session = self.make_session(name, single_func, multi=True)
                sessions.extend(session)

            return sessions

        # Simple case: If this function is not parametrized, then make
        # a simple session
        if not hasattr(func, "parametrize"):
            long_names = []
            if not multi:
                long_names.append(name)
            if func.python:
                long_names.append("{}-{}".format(name, func.python))

            session = SessionRunner(name, long_names, func, self._config, self)
            return [session]

        # Since this function is parametrized, we need to add a distinct
        # session for each permutation.
        calls = generate_calls(func, func.parametrize)
        for call in calls:
            long_names = []
            if not multi:
                long_names.append("{}{}".format(name, call.session_signature))
            if func.python:
                long_names.append(
                    "{}-{}{}".format(name, func.python, call.session_signature)
                )
                # Ensure that specifying session-python will run all parameterizations.
                long_names.append("{}-{}".format(name, func.python))
github theacodes / nox / nox / manifest.py View on Github external
if not multi:
                long_names.append("{}{}".format(name, call.session_signature))
            if func.python:
                long_names.append(
                    "{}-{}{}".format(name, func.python, call.session_signature)
                )
                # Ensure that specifying session-python will run all parameterizations.
                long_names.append("{}-{}".format(name, func.python))

            sessions.append(SessionRunner(name, long_names, call, self._config, self))

        # Edge case: If the parameters made it such that there were no valid
        # calls, add an empty, do-nothing session.
        if not calls:
            sessions.append(
                SessionRunner(name, [], _null_session_func, self._config, self)
            )

        # Return the list of sessions.
        return sessions
github theacodes / nox / nox / manifest.py View on Github external
# Since this function is parametrized, we need to add a distinct
        # session for each permutation.
        calls = generate_calls(func, func.parametrize)
        for call in calls:
            long_names = []
            if not multi:
                long_names.append("{}{}".format(name, call.session_signature))
            if func.python:
                long_names.append(
                    "{}-{}{}".format(name, func.python, call.session_signature)
                )
                # Ensure that specifying session-python will run all parameterizations.
                long_names.append("{}-{}".format(name, func.python))

            sessions.append(SessionRunner(name, long_names, call, self._config, self))

        # Edge case: If the parameters made it such that there were no valid
        # calls, add an empty, do-nothing session.
        if not calls:
            sessions.append(
                SessionRunner(name, [], _null_session_func, self._config, self)
            )

        # Return the list of sessions.
        return sessions