How to use the nox.command.run 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_command.py View on Github external
def test_fail_with_silent(capsys):
    with pytest.raises(nox.command.CommandFailed):
        nox.command.run(
            [
                PYTHON,
                "-c",
                'import sys; sys.stdout.write("out");'
                'sys.stderr.write("err"); sys.exit(1)',
            ],
            silent=True,
        )
        out, err = capsys.readouterr()
        assert "out" in err
        assert "err" in err
github theacodes / nox / tests / test_command.py View on Github external
def test_custom_stderr(capsys, tmpdir):
    with open(str(tmpdir / "err.txt"), "w+b") as stderr:
        nox.command.run(
            [
                PYTHON,
                "-c",
                'import sys; sys.stdout.write("out");'
                'sys.stderr.write("err"); sys.exit(0)',
            ],
            stderr=stderr,
        )
        out, err = capsys.readouterr()
        assert not err
        assert "out" not in out
        assert "err" not in out
        stderr.seek(0)
        tempfile_contents = stderr.read().decode("utf-8")
        assert "out" not in tempfile_contents
        assert "err" in tempfile_contents
github theacodes / nox / tests / test_command.py View on Github external
def test_custom_stdout_failed_command(capsys, tmpdir):
    with open(str(tmpdir / "out.txt"), "w+b") as stdout:
        with pytest.raises(nox.command.CommandFailed):
            nox.command.run(
                [
                    PYTHON,
                    "-c",
                    'import sys; sys.stdout.write("out");'
                    'sys.stderr.write("err"); sys.exit(1)',
                ],
                stdout=stdout,
            )
        out, err = capsys.readouterr()
        assert not out
        assert "out" not in err
        assert "err" not in err
        stdout.seek(0)
        tempfile_contents = stdout.read().decode("utf-8")
        assert "out" in tempfile_contents
        assert "err" in tempfile_contents
github theacodes / nox / tests / test_command.py View on Github external
def test_run_defaults(capsys):
    result = nox.command.run([PYTHON, "-c", "print(123)"])

    assert result is True
github theacodes / nox / tests / test_command.py View on Github external
def test_run_external_raises(tmpdir, caplog):
    caplog.set_level(logging.ERROR)

    with pytest.raises(nox.command.CommandFailed):
        nox.command.run(
            [PYTHON, "--version"], silent=True, path=tmpdir.strpath, external="error"
        )

    assert "external=True" in caplog.text
github theacodes / nox / tests / test_command.py View on Github external
def test_run_not_found():
    with pytest.raises(nox.command.CommandFailed):
        nox.command.run(["nonexistentcmd"])
github theacodes / nox / tests / test_command.py View on Github external
def test_run_silent(capsys):
    result = nox.command.run([PYTHON, "-c", "print(123)"], silent=True)

    out, _ = capsys.readouterr()

    assert "123" in result
    assert out == ""
github theacodes / nox / nox / sessions.py View on Github external
else:
            env = self.env

        # If --error-on-external-run is specified, error on external programs.
        if self._runner.global_config.error_on_external_run:
            kwargs.setdefault("external", "error")

        # Allow all external programs when running outside a sandbox.
        if not self.virtualenv.is_sandboxed:
            kwargs["external"] = True

        if args[0] in self.virtualenv.allowed_globals:
            kwargs["external"] = True

        # Run a shell command.
        return nox.command.run(args, env=env, path=self.bin, **kwargs)
github theacodes / nox / nox / virtualenv.py View on Github external
"--prefix",
            self.location,
            # Ensure the pip package is installed.
            "pip",
        ]

        if self.interpreter:
            python_dep = "python={}".format(self.interpreter)
        else:
            python_dep = "python"
        cmd.append(python_dep)

        logger.info(
            "Creating conda env in {} with {}".format(self.location_name, python_dep)
        )
        nox.command.run(cmd, silent=True, log=False)

        return True