Skip to main content

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}

Metadata

Release files for tox-local-hooks 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tox-local-hooks 0.1.3
File Size Uploaded Provenance Actions
tox-local-hooks-0.1.3.tar.gz 2.8 kB Without provenance Details for tox-local-hooks-0.1.3.tar.gz

Release files / tox-local-hooks-0.1.3.tar.gz

Download URL tox-local-hooks-0.1.3.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f4a715abadd6035c93bc3685150ceafdfd31c54dd616c58db01946fe1494a59d
BLAKE2b-256 checksum
How to use checksums
bd940395961056f08dbfb2b6d449deada7b36d0a79279dc8a8a0a42c145561bb
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for tox-local-hooks 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page