Skip to main content

Write hooks for tox in a local file

Project description

With this plugin, local tox hook implementations can be defined in a file toxhooks.py, which is in the same folder as the tox configuration file.

This will make it easier to write your own custom local hooks for tox. You just have to write the hooks in toxhooks.py (instead of creating a plugin package starting with tox- and then installing it in the same location as tox).

Example

tox.ini file

[tox]
minversion = 3.8.0
requires = tox-local-hooks
skipsdist = true

[testenv]
whitelist_externals = bash
randpwdenv = TESTPASSWORD
commands = bash -c 'echo RANDOM PASSWORD: $TESTPASSWORD'

Then create the toxhooks.py file in the same folder as tox-ini file

import pluggy, string, random

hookimpl = pluggy.HookimplMarker("tox")

@hookimpl
def tox_addoption(parser):
    parser.add_testenv_attribute(
        "randpwdenv",
        type="string",
        help="Random password environmental variable"
    )

@hookimpl(tryfirst=True)
def tox_configure(config):
    for envConf in config.envconfigs.values():
        if envConf.randpwdenv:
            pwd = ''.join(random.choice(string.ascii_letters) for _ in range(10))
            envConf.setenv[envConf.randpwdenv] = pwd

While running tox, you should be able to see the following output

RANDOM PASSWORD: {some_random_string}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tox-local-hooks-0.1.1.tar.gz (2.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page