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.3.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file tox-local-hooks-0.1.3.tar.gz.

File metadata

  • Download URL: tox-local-hooks-0.1.3.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.7

File hashes

Hashes for tox-local-hooks-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f4a715abadd6035c93bc3685150ceafdfd31c54dd616c58db01946fe1494a59d
MD5 320e0a3b62dfbb620da04a92eec2ccc9
BLAKE2b-256 bd940395961056f08dbfb2b6d449deada7b36d0a79279dc8a8a0a42c145561bb

See more details on using hashes here.

Supported by

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