How to use the nox.command.CommandFailed 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 func(session):
            raise nox.command.CommandFailed()
github theacodes / nox / tests / test_sessions.py View on Github external
def test_run_external_with_error_on_external_run_condaenv(self):
        session, runner = self.make_session_and_runner()
        runner.venv = mock.create_autospec(nox.virtualenv.CondaEnv)
        runner.venv.env = {}
        runner.venv.bin = "/path/to/env/bin"

        runner.global_config.error_on_external_run = True

        with pytest.raises(nox.command.CommandFailed, match="External"):
            session.run(sys.executable, "--version")
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 / nox / sessions.py View on Github external
def _run_func(self, func, args, kwargs):
        """Legacy support for running a function through :func`run`."""
        self.log("{}(args={!r}, kwargs={!r})".format(func, args, kwargs))
        try:
            return func(*args, **kwargs)
        except Exception as e:
            logger.exception("Function {!r} raised {!r}.".format(func, e))
            raise nox.command.CommandFailed()
github saltstack / salt / noxfile.py View on Github external
def _runtests(session, coverage, cmd_args):
    # Create required artifacts directories
    _create_ci_directories()
    try:
        if coverage is True:
            _run_with_coverage(session, 'coverage', 'run', os.path.join('tests', 'runtests.py'), *cmd_args)
        else:
            cmd_args = ['python', os.path.join('tests', 'runtests.py')] + list(cmd_args)
            env = None
            if IS_DARWIN:
                # Don't nuke our multiprocessing efforts objc!
                # https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
                env = {'OBJC_DISABLE_INITIALIZE_FORK_SAFETY': 'YES'}
            session.run(*cmd_args, env=env)
    except CommandFailed:
        # Disabling re-running failed tests for the time being
        raise

        # pylint: disable=unreachable
        names_file_path = os.path.join('artifacts', 'failed-tests.txt')
        session.log('Re-running failed tests if possible')
        session.install('--progress-bar=off', 'xunitparser==1.3.3', silent=PIP_INSTALL_SILENT)
        session.run(
            'python',
            os.path.join('tests', 'support', 'generate-names-file-from-failed-test-reports.py'),
            names_file_path
        )
        if not os.path.exists(names_file_path):
            session.log(
                'Failed tests file(%s) was not found. Not rerunning failed tests.',
                names_file_path
github theacodes / nox / nox / command.py View on Github external
"""Finds the full path to an executable."""
    full_path = None

    if path:
        full_path = py.path.local.sysfind(program, paths=[path])

    if full_path:
        return full_path.strpath

    full_path = py.path.local.sysfind(program)

    if full_path:
        return full_path.strpath

    logger.error("Program {} not found.".format(program))
    raise CommandFailed("Program {} not found".format(program))