How to use tox - 10 common examples

To help you get started, we’ve selected a few tox 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 ansible / pytest-mp / setup.py View on Github external
def run_tests(self):
        import tox
        errno = tox.cmdline(self.tox_args)
        sys.exit(errno)
github tox-dev / tox-venv / tests / test_z_cmdline.py View on Github external
def test_exit_code(initproj, cmd, exit_code, mocker):
    """ Check for correct InvocationError, with exit code,
        except for zero exit code """
    import tox.exception

    mocker.spy(tox.exception, "exit_code_str")
    tox_ini_content = "[testenv:foo]\ncommands=python -c 'import sys; sys.exit({:d})'".format(
        exit_code
    )
    initproj("foo", filedefs={"tox.ini": tox_ini_content})
    cmd()
    if exit_code:
        # need mocker.spy above
        assert tox.exception.exit_code_str.call_count == 1
        (args, kwargs) = tox.exception.exit_code_str.call_args
        assert kwargs == {}
        (call_error_name, call_command, call_exit_code) = args
        assert call_error_name == "InvocationError"
        # quotes are removed in result.out
        # do not include "python" as it is changed to python.EXE by appveyor
        expected_command_arg = " -c 'import sys; sys.exit({:d})'".format(exit_code)
        assert expected_command_arg in call_command
github tox-dev / tox-venv / tests / test_z_cmdline.py View on Github external
cmd()
    if exit_code:
        # need mocker.spy above
        assert tox.exception.exit_code_str.call_count == 1
        (args, kwargs) = tox.exception.exit_code_str.call_args
        assert kwargs == {}
        (call_error_name, call_command, call_exit_code) = args
        assert call_error_name == "InvocationError"
        # quotes are removed in result.out
        # do not include "python" as it is changed to python.EXE by appveyor
        expected_command_arg = " -c 'import sys; sys.exit({:d})'".format(exit_code)
        assert expected_command_arg in call_command
        assert call_exit_code == exit_code
    else:
        # need mocker.spy above
        assert tox.exception.exit_code_str.call_count == 0
github tox-dev / tox / tests / unit / package / test_package.py View on Github external
def test_sdist_latest(tmpdir, newconfig):
    distshare = tmpdir.join("distshare")
    config = newconfig(
        [],
        """
            [tox]
            distshare={}
            sdistsrc={{distshare}}/pkg123-*
    """.format(
            distshare
        ),
    )
    p = distshare.ensure("pkg123-1.4.5.zip")
    distshare.ensure("pkg123-1.4.5a1.zip")
    session = Session(config)
    _, dist = get_package(session)
    assert dist == p
github tox-dev / tox-travis / tests / test_hacks.py View on Github external
def test_subcommand_test_post_hook(self, mocker):
        """It should return the same retcode, but run the hook."""
        subcommand_test = mocker.patch('tox.session.Session.subcommand_test',
                                       return_value=42)
        tox_subcommand_test_post = mocker.Mock()
        subcommand_test_monkeypatch(tox_subcommand_test_post)

        import tox.session
        session = mocker.Mock()

        real_subcommand_test = tox.session.Session.subcommand_test
        # Python 2 compat
        real_subcommand_test = getattr(
            real_subcommand_test, '__func__', real_subcommand_test)

        assert real_subcommand_test(session) == 42
        subcommand_test.assert_called_once_with(session)
        tox_subcommand_test_post.assert_called_once_with(session.config)
github tox-dev / tox-venv / tests / test_z_cmdline.py View on Github external
commands_pre = python -c 'print("START")'
            commands = python -c 'print("OK")'
                       - python -c 'raise SystemExit(1)'
                       python -c 'raise SystemExit(2)'
                       python -c 'print("SHOULD NOT HAPPEN")'
            commands_post = python -c 'print("END")'
        """
        },
    )
    json_path = cwd / "res.json"
    result = cmd("--result-json", json_path)
    result.assert_fail()
    data = json.loads(json_path.read_text(encoding="utf-8"))

    assert data["reportversion"] == "1"
    assert data["toxversion"] == tox.__version__

    for env_data in data["testenvs"].values():
        for command_type in ("setup", "test"):
            if command_type not in env_data:
                assert False, "missing {}".format(command_type)
            for command in env_data[command_type]:
                assert isinstance(command["command"], list)
                assert command["output"]
                assert "retcode" in command
                assert isinstance(command["retcode"], int)
        # virtualenv, deps install, package install, freeze
        assert len(env_data["setup"]) == 4
        # 1 pre + 3 command + 1 post
        assert len(env_data["test"]) == 5
        assert isinstance(env_data["installed_packages"], list)
        pyinfo = env_data["python"]
github tox-dev / tox / tests / unit / test_z_cmdline.py View on Github external
def test_log_pcall(self, mocksession):
        mocksession.logging_levels(quiet=Verbosity.DEFAULT, verbose=Verbosity.INFO)
        mocksession.config.logdir.ensure(dir=1)
        assert not mocksession.config.logdir.listdir()
        with mocksession.newaction("what", "something") as action:
            action.popen(["echo"])
            match = mocksession.report.getnext("logpopen")
            log_name = py.path.local(match[1].split(">")[-1].strip()).relto(
                mocksession.config.logdir
            )
            assert log_name == "what-0.log"
github tox-dev / tox-venv / tests / test_z_cmdline.py View on Github external
def test_log_pcall(self, mocksession):
        mocksession.logging_levels(quiet=Verbosity.DEFAULT, verbose=Verbosity.INFO)
        mocksession.config.logdir.ensure(dir=1)
        assert not mocksession.config.logdir.listdir()
        with mocksession.newaction("what", "something") as action:
            action.popen(["echo"])
            match = mocksession.report.getnext("logpopen")
            log_name = py.path.local(match[1].split(">")[-1].strip()).relto(
                mocksession.config.logdir
            )
            assert log_name == "what-0.log"
github a-feld / pytest-skippy / setup.py View on Github external
def run_tests(self):
        import tox
        tox.cmdline(self.test_args)
github tox-dev / tox / tests / unit / test_venv.py View on Github external
        @tox.hookimpl
        def tox_runtest_pre(self):
            log.append("started")