Plugin API reference¶
tox objects¶
register¶
Manages the tox environment registry.
- class tox.tox_env.register.ToxEnvRegister¶
Bases:
objecttox environment registry.
- property env_runners¶
The run environment types currently defined.
- property default_env_runner¶
The default run environment type.
- add_run_env(of_type)¶
Define a new run tox environment type.
- add_package_env(of_type)¶
Define a new packaging tox environment type.
- Parameters:
of_type (
type[PackageToxEnv]) – the new packaging environment type- Return type:
- runner(name)¶
Lookup a run tox environment type by name.
- tox.tox_env.register.REGISTER¶
the tox register
config¶
- class tox.config.cli.parser.ArgumentParserWithEnvAndConfig(*args, **kwargs)¶
Bases:
ArgumentParserArgument parser which updates its defaults by checking the configuration files and environmental variables.
- Parameters:
args (
Any) – positional arguments passed toargparse.ArgumentParserkwargs (
Any) – keyword arguments passed toargparse.ArgumentParser,file_configselects the configuration the defaults are read from
- Variables:
file_config – the configuration the defaults are read from
- fix_defaults()¶
Apply the environment variable and config file defaults to all arguments, sub-parsers included.
- Return type:
- fix_default(action)¶
Set the default of an argument from its environment variable or config file value, when one is set.
- Parameters:
action (
Action) – the argument to update- Raises:
RuntimeError – when a sub-parser was added without using the tox parser
- Return type:
- static get_type(action)¶
Get the type the values of an argument are converted to.
- class tox.config.cli.parser.ToxParser(*args, root=False, add_cmd=False, **kwargs)¶
Bases:
ArgumentParserWithEnvAndConfigArgument parser for tox.
- Parameters:
args (
Any) – positional arguments passed toArgumentParserWithEnvAndConfigroot (
bool) – whether the base options are added, set for the top-level parseradd_cmd (
bool) – whether a sub-command group is added to take the tox commandskwargs (
Any) – keyword arguments passed toArgumentParserWithEnvAndConfig
- Variables:
of_cmd (
str|None) – the command this parser was added for,Nonefor the top-level parserinherit (
frozenset[str]) – the option groups,coreandenv, this parser takes from its parenthandlers (
dict[str,tuple[ToxParser,Callable[[State],int]]]) – the command and alias names mapped to their sub-parser and handler
- classmethod base()¶
Create a root parser without the help option.
- Return type:
- Returns:
the root parser
- classmethod core()¶
Create the root parser of the tox command, which accepts sub-commands.
- Return type:
- Returns:
the root parser
- add_command(cmd, aliases, help_msg, handler, *, inherit=frozenset({'core', 'env'}))¶
Register a sub-command with its own parser and handler.
- Parameters:
cmd (
str) – the name of the sub-commandaliases (
Sequence[str]) – other names the sub-command can be invoked withhelp_msg (
str) – the help text of the sub-commandhandler (
Callable[[State],int]) – the function that runs the sub-commandinherit (
frozenset[str]) – the option groups the sub-command inherits from the root parser
- Return type:
- Returns:
the parser of the sub-command
- Raises:
RuntimeError – when this parser does not accept sub-commands
- add_argument_group(*args, **kwargs)¶
- Return type:
_ArgumentGroup- Overrides:
- add_argument(*args, of_type=None, **kwargs)¶
- add_argument(option_string, option_string, ..., name=value, ...)
- Return type:
- Overrides:
- class tox.config.cli.parser.Parsed(**kwargs)¶
Bases:
NamespaceCLI options.
The annotations below declare the type each option has once its command registered it; an option belonging to another command is absent at runtime, so shared code paths read it via
getattrwith a fallback.- verbose¶
the number of
-vflags passed
- quiet¶
the number of
-qflags passed
- colored¶
yeswhen the output is colored,nootherwise
- stderr_color¶
the color used for stderr output
- exit_and_dump_after¶
seconds after which tox dumps its threads and exits,
0disables it
- config_file¶
the configuration file or folder passed with
-c, if any
- work_dir¶
the tox working directory, if one was given
- root_dir¶
the project root directory, if one was given
- override¶
the configuration overrides passed with
--override
- command¶
the name of the sub-command to run
- remainder¶
the arguments passed after
--
- env¶
the environments selected with
-e
- labels¶
the environment labels selected with
-m
- factors¶
the environment factors selected with
-f
- skip_env¶
the regular expression of environments to exclude
- default_runner¶
the tox run engine used when an environment does not name one
- result_json¶
the file the JSON result report is written to, if any
- no_capture¶
whether output capture is disabled
- hash_seed¶
the value of
PYTHONHASHSEEDfor the commands,Nonewhen it is not set
- discover¶
the Python executables to try first during discovery
- list_dependencies¶
whether the dependencies installed during environment setup are listed
- recreate¶
whether environments are recreated before use
- no_test¶
whether the test commands are skipped
- package_only¶
whether only the package is built
- install_pkg¶
the package to install instead of building the project, if any
- fail_fast¶
whether execution stops after the first environment failure
- develop¶
whether the package is installed in development mode
- no_recreate_pkg¶
whether packaging environments are kept when
recreateis set
- skip_pkg_install¶
whether the package installation is skipped
- skip_env_install¶
whether dependency and package installation is skipped
- skip_missing_interpreters¶
whether missing interpreters are skipped,
configdefers to the configuration
- parallel¶
the number of environments run in parallel
- parallel_live¶
whether the output of parallel environments is shown live
- parallel_no_spinner¶
whether the spinner is disabled in parallel mode
- no_provision¶
whether provisioning is skipped and fails instead, or the path its metadata is written to
- no_recreate_provision¶
whether the provisioning environment is kept when
recreateis set
- devenv_path¶
the directory of the development environment
- force_dep¶
the dependency requirements forced into the environments
- site_packages¶
whether the environments can see the system site packages
- always_copy¶
whether the environments copy files instead of linking them
- pre¶
whether pre-release versions are installed
- property verbosity¶
The reporting verbosity: the
-vcount minus the-qcount, never below zero.
- property is_colored¶
Truewhen the output is colored.
- class tox.config.cli.parse.Options(parsed, pos_args, source, cmd_handlers, log_handler)¶
Bases:
NamedTupleThe parsed command line options together with the state needed to run tox.
- Parameters:
parsed (
Parsed) – the parsed command line optionspos_args (
Sequence[str] |None) – the positional arguments passed after--source (
Source) – the source the configuration is read fromcmd_handlers (
dict[str,Callable[[State],int]]) – the handlers of the sub-commands, keyed by command namelog_handler (
ToxHandler) – the handler that reports the log output
- class tox.config.main.Config(config_source, options, root, pos_args, work_dir, extra_envs)¶
Bases:
objectMain configuration object for tox.
- Parameters:
config_source (
Source) – the source the configuration is read fromoptions (
Parsed) – the parsed command line optionsroot (
Path) – the project root directory, where the configuration file ispos_args (
Sequence[str] |None) – the positional arguments passed after--work_dir (
Path) – the directory where tox keeps its own filesextra_envs (
Iterable[str]) – the environments to add to the configured ones
- Variables:
memory_seed_loaders (
defaultdict[str,list[MemoryLoader]]) – the in-memory loaders that seed the environments by name
- reject_package_discovery()¶
Stop discovery when a setting cannot resolve yet.
- Raises:
HandledError – if package discovery is active
- Return type:
- property in_package_discovery¶
Whether the current lookup is choosing a package mode.
- property core¶
The core configuration, loaded on first access.
- property src_path¶
The location of the tox configuration source.
- property work_dir¶
The working directory for this project.
- property options¶
The parsed command line options.
- property overrides¶
The configuration overrides keyed by their target namespace.
- package_discovery()¶
Resolve core settings without caching values or defining environments.
- Yields:
None– control while discovery mode is active
- pos_args(to_path, *, program_first=False)¶
Get the positional arguments passed after
--, with path arguments made relative to a directory.- Parameters:
- Return type:
- Returns:
the positional arguments, or
Nonewhen none were passed
- sections()¶
Iterate over the sections of the configuration source.
- Yields:
Section– the sections, in the order the source defines them
- factor_labels(env_name)¶
Get the factor labels defined for an environment.
- get_env(item, package=False, loaders=None)¶
Return the configuration for a given tox environment (will create if not exist yet).
- Parameters:
- Return type:
- Returns:
the tox environments config
- get_section_config(section, base, of_type, for_env, loaders=None)¶
Get the configuration set of a section, creating and caching it on first use.
- Parameters:
section (
Section) – the section to loadbase (
list[str] |None) – the base sections the configuration inherits fromof_type (
type[T]) – the configuration set type to createfor_env (
str|None) – the environment name,Nonefor the core configurationloaders (
Sequence[Loader[Any]] |None) – extra loaders to read values from, appended after the source loaders
- Return type:
T- Returns:
the configuration set of the section
- class tox.config.loader.section.Section(prefix, name)¶
Bases:
objecttox configuration section.
- Parameters:
- SEP = ':'¶
string used to separate the prefix and the section in the key
- classmethod from_key(key)¶
Create a section from a section key.
- property key¶
The section key: the prefix and the name joined by the separator, the prefix left out when unset.
- property prefix¶
The prefix of the section,
Nonewhen it has none.
- property name¶
The name of the section.
- class tox.config.loader.api.ConfigLoadArgs(chain, name, env_name)¶
Bases:
objectArguments that help loading a configuration value.
- copy()¶
- Return type:
- Returns:
create a copy of the object
- class tox.config.sets.ConfigSet(conf, section, env_name)¶
Bases:
ABCA set of configuration that belong together (such as a tox environment settings, core tox settings).
- Parameters:
- loaders¶
active configuration loaders, can alter to change configuration values
- abstractmethod register_config()¶
Register the configuration keys this set provides.
- Return type:
- load(item, chain=None)¶
Get the config value for a given key (will materialize in case of dynamic config).
- property name¶
The name of the section this set reads its configuration from.
- property env_name¶
The name of the environment this set belongs to,
Nonefor the core configuration.
- __iter__()¶
- __contains__(item)¶
Check if a configuration key is within the config set.
- get_configs()¶
Iterate over the config definitions, one per config.
- Yields:
ConfigDefinition[Any] – the definition of each config, keyed by its first key
- mark_finalized()¶
Mark the set as final, after which no further configuration can be added.
- Return type:
- add_config(keys, of_type, default, desc, post_process=None, factory=None)¶
Add configuration value.
- Overloads:
keys (
str|Sequence[str]), of_type (type[V]), default (Callable[[Config,str|None],V]), desc (str), post_process (Callable[[V],V] |None) =None, factory (Callable[[object],Any] |None) =None→ConfigDynamicDefinition[V]keys (
str|Sequence[str]), of_type (type[V]), default (None), desc (str), post_process (Callable[[V|None],V|None] |None) =None, factory (Callable[[object],Any] |None) =None→ConfigDynamicDefinition[V|None]keys (
str|Sequence[str]), of_type (type[V]), default (V), desc (str), post_process (Callable[[V],V] |None) =None, factory (Callable[[object],Any] |None) =None→ConfigDynamicDefinition[V]keys (
str|Sequence[str]), of_type (Union), default (Callable[[Config,str|None],V]), desc (str), post_process (Callable[[V],V] |None) =None, factory (Callable[[object],Any] |None) =None→ConfigDynamicDefinition[V]keys (
str|Sequence[str]), of_type (Union), default (Callable[[Config,str|None],V|None] |V|None), desc (str), post_process (Callable[[V|None],V|None] |None) =None, factory (Callable[[object],Any] |None) =None→ConfigDynamicDefinition[V|None]keys (
str|Sequence[str]), of_type (Union), default (Callable[[Config,str|None],V] |V), desc (str), post_process (Callable[[V],V] |None) =None, factory (Callable[[object],Any] |None) =None→ConfigDynamicDefinition[V]
- Parameters:
keys (
str|Sequence[str]) – the keys under what to register the config (first is primary key)default (
Callable[[Config,str|None],V] |V|None) – the default value of the config valuedesc (
str) – a help message describing the configurationpost_process (
Callable[[V],V] |None) – a callback to post-process the configuration value after it has been loadedfactory (
Callable[[object],Any] |None) – factory method used to build contained objects (ifof_typeis a container type it should perform the contained item creation, otherwise creates objects that match the type)
- Returns:
the new dynamic config definition
- Raises:
RuntimeError – when the set has been marked final
- add_constant(keys, desc, value)¶
Add a constant value.
- Parameters:
- Return type:
- Returns:
the new constant config value
- Raises:
RuntimeError – when the set has been marked final
- is_constant(item)¶
Check whether a configuration key is a constant.
- get(item, of_type)¶
Get the config value for a given key, verified to be of the declared type.
Unlike
load()and[]— which returnAny— the value is checked againstof_typeat runtime (container types by their unsubscripted origin, solist[str]checkslist) and returned as that type.Added in version 4.59.
- get_optional(item, of_type)¶
Get the config value for a key that may be unset, verified to be of the declared type or
None.Use this over
get()for keys registered with aNonedefault, such asmin_version.Added in version 4.62.
- unused()¶
- class tox.config.sets.CoreConfigSet(conf, section, root, src_path)¶
Bases:
ConfigSetConfiguration set for the core tox config.
- Parameters:
- register_config()¶
Register the configuration keys this set provides.
- Return type:
- Overrides:
- class tox.config.sets.EnvConfigSet(conf, section, env_name)¶
Bases:
ConfigSetConfiguration set for a tox environment.
- Parameters:
- Variables:
- default_set_env_loader¶
- exported_set_env_loader¶
- register_config()¶
Register the configuration keys this set provides.
- Return type:
- Overrides:
- class tox.config.of_type.ConfigDefinition[T](keys, desc)¶
-
Abstract base class for configuration definitions.
- Parameters:
- class tox.config.of_type.ConfigDynamicDefinition[T](keys, desc, of_type, default, post_process=None, factory=None)¶
Bases:
ConfigDefinition[T]A configuration definition that comes from a source (such as in memory, an ini file, a toml file, etc.).
- Parameters:
keys (
Iterable[str]) – the configuration keys, the first one is the name, the others are aliasesdesc (
str) – the help text describing the configurationof_type (
type[T] |Union) – the type the loaded value is converted todefault (
Callable[[Config,str|None],T] |T|None) – the value, or a callable computing it, used when the configuration is not setpost_process (
Callable[[T],T] |None) – a callable applied to the converted valuefactory (
Callable[[object],T] |None) – the callable that builds the objects of the type, for container and custom types
- overwrite(value)¶
Force the configuration to the given value, replacing any constant or already loaded one.
- Parameters:
value (
T) – the new value- Return type:
- Overrides:
- class tox.config.of_type.ConfigConstantDefinition[T](keys, desc, value)¶
Bases:
ConfigDefinition[T]A configuration definition whose value is defined upfront (such as the tox environment name).
- Parameters:
- overwrite(value)¶
Force the configuration to the given value, replacing any constant or already loaded one.
- Parameters:
value (
T) – the new value- Return type:
- Overrides:
- class tox.config.source.api.Source(path)¶
Bases:
ABCSource is able to return a configuration value (for either the core or per environment source).
- Parameters:
path (
Path) – the path of the configuration file- Variables:
FILENAME – the name of the configuration file
- FILENAME = ''¶
- path¶
the path to the configuration source
- get_loaders(section, base, override_map, conf)¶
Return a loader that loads settings from a given section name.
- abstractmethod transform_section(section)¶
Transform a section before it is used, for example to add a prefix.
- abstractmethod get_loader(section, override_map)¶
Get the loader that reads the values of a section.
- abstractmethod get_base_sections(base, in_section)¶
Get the base sections a section inherits from.
- abstractmethod sections()¶
Return a loader that loads the core configuration values.
- abstractmethod envs(core_conf)¶
- Parameters:
core_conf (
CoreConfigSet) – the core configuration set- Return type:
- Returns:
a list of environments defined within this source
- abstractmethod get_tox_env_section(item)¶
Get the section of a tox environment.
- class tox.config.source.api.FactorLabelSource(*args, **kwargs)¶
Bases:
ProtocolA configuration source that defines factor labels for each environment.
- class tox.config.loader.api.Override(value)¶
Bases:
objectAn override for config definitions.
- Parameters:
value (
str) – the[namespace.]key[+]=valuetext of the override- Variables:
append – whether the value is appended to a list instead of replacing it
namespace – the dotted section path the key belongs to
key – the name of the configuration key the override applies to
- final class tox.config.set_env.SetEnvReference(config, args, shape)¶
Bases:
objectKeep overrides pending until the consuming environment has registered its keys.
- Parameters:
config (
SetEnv) – theset_envthe value is written toargs (
ConfigLoadArgs) – the load arguments the value is resolved withshape (
Literal['string','table','array']) – the form the value was written in, a string, a table or an array
- class tox.config.set_env.SetEnvEntry¶
Bases:
TypedDictA single
set_envvalue in structured (TOML) form.- Variables:
value (
str|MatchExpression) – the value, a string or areplacetable, the marker applies tomarker (
NotRequired[str]) – the environment marker that decides whether the value applies
- class tox.config.set_env.SetEnv(raw, name, env_name, root, *, substituted=False)¶
Bases:
objectThe environment variables of a tox environment, as set by its
set_envsetting.- Parameters:
raw (
str|dict[str,str|MatchExpression|SetEnvEntry] |SetEnvReference|list[dict[str,str|MatchExpression|SetEnvEntry] |SetEnvReference]) – the value of theset_envsettingname (
str) – the name of the setting the value comes fromenv_name (
str|None) – the name of the environment the setting belongs to,Nonewhen unknownroot (
Path) – the root directory of the projectsubstituted (
bool) – whether the value is text produced by a substitution
- Variables:
- use_replacer(value, args)¶
Use a replacer to expand the values of the environment variables.
- Parameters:
value (
Replacer) – the replacer to useargs (
ConfigLoadArgs) – the args of the configuration load
- Return type:
- load(item, args=None)¶
Get the value of an environment variable.
- Parameters:
item (
str) – the name of the environment variableargs (
ConfigLoadArgs|None) – the args of the configuration load, a new set is created whenNone
- Return type:
- Returns:
the value of the environment variable
- lines()¶
Get the environment variables as
KEY=VALUElines, in the form they are written in the configuration.- Return type:
- Returns:
the lines, separated by newlines
- raw(args, *, resolve=True)¶
Preserve lazy values and markers when another section includes this configuration.
- Parameters:
args (
ConfigLoadArgs) – the load arguments the values are resolved withresolve (
bool) – whether pending replacements are resolved first
- Return type:
- Returns:
the entries keyed by name, each holding its value and optional marker
- export(values)¶
Set tox’s own variables over the configured ones, resolved on first read.
They come from settings that may read
set_envthrough{env:...}, so reading them here would recurse.
- extend(other)¶
Appended blocks override base keys; explicit keys in the same override win.
- class tox.config.set_env.Replacer(*args, **kwargs)¶
Bases:
ProtocolExpand the replacements in the value of an environment variable.
- class tox.config.loader.replacer.MatchExpression(expr, term_pos=None, *, host=False, literal=False)¶
Bases:
objectAn expression that is handled specially by the Replacer.
- Parameters:
- classmethod parse_and_split_to_terminator(value, terminator='', split=None)¶
Tokenize value to up terminator character.
If split is given, multiple arguments will be returned.
Returns list of arguments (list of str or MatchExpression) and final character position examined in value.
This function recursively calls itself via _next_replace_expression.
- Parameters:
- Return type:
- Returns:
the parsed arguments and the position where tokenizing stopped
- Raises:
MatchError – when the text does not form a valid expression
- class tox.config.loader.replacer.MatchError¶
Bases:
ExceptionCouldn’t find end terminator in MatchExpression.
- class tox.config.loader.api.Loader[T](section, overrides)¶
-
Loader loads configuration values and converts it.
- abstractmethod found_keys()¶
A list of configuration keys found within the configuration.
- property section¶
Return the section of the configuration from where the values are extracted.
- load(key, of_type, factory, conf, args, all_keys=())¶
Load a value (raw and then convert).
- Parameters:
key (
str) – the key under it livesfactory (
Callable[[object],V] |None) – factory method to build the objectconf (
Config|None) – the configuration object of this tox session (needed to manifest the value)args (
ConfigLoadArgs) – the config load argumentsall_keys (
Iterable[str]) – all alias keys for this config entry (to collect overrides from any alias)
- Return type:
V- Returns:
the converted type
- Raises:
KeyError – when the key is not present in any source, or, as
AppendOverridesError, when the source does not set the key but has onlykey+=valueoverrides for itValueError – when the value cannot be converted to the requested type
- abstractmethod load_raw(key, conf, env_name)¶
Load the raw object from the config store.
- build(key, of_type, factory, conf, raw, args)¶
Materialize the raw configuration value from the loader.
- Parameters:
- Return type:
V- Returns:
the object built from the raw value
- substitute(value, conf, args, *, of_type)¶
Apply this loader’s replacements to a raw string.
- set_env_reference(raw, overrides, conf, args)¶
Wrap a raw value in a reference that loads it as a
set_envvalue.- Parameters:
raw (
T) – the value as written in the configuration,set_envtable or stringconf (
Config) – the global configargs (
ConfigLoadArgs) – env args
- Return type:
- Returns:
the set env reference
- Raises:
ValueError – when the reference is circular
- class tox.config.loader.memory.MemoryLoader(**kwargs)¶
-
Loads configuration directly from data in memory.
- Parameters:
kwargs (
Any) – the configuration values, keyed by name- Variables:
raw (
dict[str,Any]) – the configuration values as set in memory
- load_raw(key, conf, env_name)¶
Load the raw object from the config store.
- found_keys()¶
A list of configuration keys found within the configuration.
- Return type:
- Returns:
the keys found within the configuration
- Overrides:
- static to_bool(value)¶
Convert to boolean.
- Parameters:
value (
Any) – the value to convert- Return type:
- Returns:
a boolean representation of the value
- Overrides:
- static to_str(value)¶
Convert to string.
- Parameters:
value (
Any) – the value to convert- Return type:
- Returns:
a string representation of the value
- Overrides:
- static to_list(value, of_type)¶
Convert to list.
- static to_set(value, of_type)¶
Convert to set.
- static to_dict(value, of_type)¶
Convert to dictionary.
- static to_path(value)¶
Convert to path.
- Parameters:
value (
Any) – the value to convert- Return type:
- Returns:
path representation of the value
- Overrides:
- static to_command(value)¶
Convert to a command to execute.
- Parameters:
value (
Any) – the value to convert- Return type:
- Returns:
command representation of the value
- Overrides:
- class tox.config.loader.convert.Convert[T]¶
-
A class that converts a raw type to a given tox (python) type.
- to(raw, of_type, factory)¶
Convert given raw type to python type.
- abstractmethod static to_list(value, of_type)¶
Convert to list.
- abstractmethod static to_set(value, of_type)¶
Convert to set.
- abstractmethod static to_dict(value, of_type)¶
Convert to dictionary.
- abstractmethod static to_path(value)¶
Convert to path.
- Parameters:
value (
T) – the value to convert- Return type:
- Returns:
path representation of the value
- abstractmethod static to_bool(value)¶
Convert to boolean.
- Parameters:
value (
T) – the value to convert- Return type:
- Returns:
a boolean representation of the value
- abstractmethod static to_command(value)¶
Convert to a command to execute.
- Parameters:
value (
T) – the value to convert- Return type:
- Returns:
command representation of the value
- abstractmethod static to_env_list(value)¶
Convert to a tox EnvList.
- Parameters:
value (
T) – the value to convert- Return type:
- Returns:
a list of tox environments from the value
- class tox.config.types.Command(args)¶
Bases:
objectA command to execute.
- ignore_exit_code¶
a flag indicating if the exit code should be ignored
- invert_exit_code¶
a flag for flipped exit code (non-zero = success, 0 = error)
- args¶
the command line arguments
- property raw_args¶
The arguments with the exit code prefix,
-to ignore the exit code or!to invert it.
- property shell¶
A shell representation of the command, platform dependent.
- class tox.config.types.FactorGroup(*, values, default=None, env_values=dict())¶
Bases:
objectdefaultstands in wherever an environment name carries none ofvalues.- Parameters:
- values¶
- default¶
- env_values¶
- tox.config.loader.convert.Factory¶
Callable that converts a raw value to the target type, or
Nonewhen no conversion is needed.
environments¶
- class tox.tox_env.api.ToxEnv(create_args)¶
Bases:
ABCA tox environment.
- journal¶
handler to the tox reporting system
- conf¶
the config set to use for this environment
- core¶
the core tox config set
- options¶
CLI options
- log_handler¶
handler to the tox reporting system
- abstractmethod static id()¶
The identifier of the tox environment type, used to select it in the configuration.
- Return type:
- Returns:
the identifier
- abstract property installer¶
The installer that installs the packages of the environment.
- register_config()¶
Register the configuration keys every tox environment has, such as its name and labels.
- Return type:
- property name¶
The name of the tox environment, such as
py313.
- abstract property executor¶
The executor that runs the commands of the environment.
- abstract property runs_on_platform¶
The platform the environment runs on, such as
unixorwin32.
- property env_dir¶
The environment folder of the tox environment.
- property cache¶
The cache of the environment, which stores the state of its last setup.
- property env_tmp_dir¶
The temp folder of the tox environment.
- property env_log_dir¶
The log folder of the tox environment.
- teardown()¶
Tear the environment down, once, and notify the plugins that it is torn down.
- Return type:
- execute(cmd, stdin, show=None, cwd=None, run_id='', executor=None, *, capture=False)¶
Execute a command and wait for its outcome.
- Parameters:
stdin (
StdinSource) – permitted standard input sourceshow (
bool|None) – whether to display output, orNoneto follow verbositycwd (
Path|None) – working directory, orNonefor the project rootrun_id (
str) – label for command logsexecutor (
Execute|None) – executor override, orNonefor this environment’s executorcapture (
bool) – capture output even in no-capture mode
- Return type:
- Returns:
completed command outcome
- Raises:
SystemExit – if execution was interrupted
ValueError – if the command is empty
RuntimeError – when the execution produced no outcome
- execute_async(cmd, stdin, show=None, cwd=None, run_id='', executor=None, *, capture=False)¶
Run a command while exposing its execution status.
- Parameters:
stdin (
StdinSource) – permitted standard input sourceshow (
bool|None) – whether to display output, orNoneto follow verbositycwd (
Path|None) – working directory, orNonefor the project rootrun_id (
str) – label for command logsexecutor (
Execute|None) – executor override, orNonefor this environment’s executorcapture (
bool) – capture output even in no-capture mode
- Raises:
SystemExit – if execution was interrupted
ValueError – if the command is empty
- Yields:
ExecuteStatus– context manager yielding the command’s execution status
- property environment_variables¶
The environment variables the commands of the environment run with.
- allow_post_commands_after_interrupt(enabled)¶
Context manager to allow commands_post execution after interrupt when enabled.
- class tox.tox_env.api.ToxEnvCreateArgs(conf, core, options, journal, log_handler)¶
Bases:
NamedTupleArguments to pass on when creating a tox environment.
- Parameters:
conf (
EnvConfigSet) – the configuration of the environmentcore (
CoreConfigSet) – the core configuration of toxoptions (
Parsed) – the parsed command line optionsjournal (
EnvJournal) – the journal the environment records its results inlog_handler (
ToxHandler) – the handler that reports the output of the environment
- class tox.tox_env.runner.RunToxEnv(create_args)¶
-
The base of the tox environments that run commands.
- Parameters:
create_args (
ToxEnvCreateArgs) – the arguments the environment is created with- Variables:
package_env (
PackageToxEnv|None) – the packaging environment the run environment uses,Nonewhen it uses none
- property environment_variables¶
The environment variables the commands of the environment run with.
- Overrides:
- register_config()¶
Register the configuration keys every tox environment has, such as its name and labels.
- Return type:
- Overrides:
- property package_envs¶
The packaging environments the run environment uses, followed by the ones they depend on.
- interrupt()¶
Interrupt the execution of a tox environment.
- Return type:
- Overrides:
- get_package_env_types()¶
Get the packaging environment types the run environment uses.
- class tox.tox_env.package.PackageToxEnv(create_args)¶
-
The base of the tox environments that build a package to install into the run environments.
- Parameters:
create_args (
ToxEnvCreateArgs) – the arguments the environment is created with
- register_config()¶
Register the configuration keys every tox environment has, such as its name and labels.
- Return type:
- Overrides:
- abstractmethod perform_packaging(for_env)¶
Build the packages of the environment.
- Parameters:
for_env (
EnvConfigSet) – the configuration of the run environment the packages are for- Return type:
- Returns:
the packages that were built
- register_run_env(run_env)¶
Register a run environment that uses the packages of this environment.
- mark_active_run_env(run_env)¶
Mark a run environment as active, so the packages are kept until it is torn down.
- teardown_env(conf)¶
Tear the packaging environment down, once no run environment uses it.
- Parameters:
conf (
EnvConfigSet) – the configuration of the run environment that is torn down- Return type:
- abstractmethod child_pkg_envs(run_conf)¶
Get the packaging environments the packaging environment of a run environment depends on.
- Parameters:
run_conf (
EnvConfigSet) – the configuration of the run environment- Return type:
- Returns:
the packaging environments
journal¶
report¶
- Handler.name¶
A standard handler stores its name for lookup. Tox reports the active environment name instead and ignores assignments to this attribute.
- class tox.report.ToxHandler(level, is_colored, out_err)¶
Bases:
StreamHandlerControls tox output.
- Parameters:
level (
int) – the minimum level of the messages to showis_colored (
bool) – whether the messages are coloredout_err (
tuple[TextIOWrapper,TextIOWrapper]) – the standard output and error streams to write to
- property stdout¶
The current standard output.
- property name¶
The current tox environment name.
- Setter accepts:
- Overrides:
- with_context(name)¶
Set a new tox environment context.
- property stderr¶
The current standard error.
- class tox.report.HandledError¶
Bases:
RuntimeErrorError that has been handled so no need for stack trace.
execute¶
- class tox.execute.request.ExecuteRequest(cmd, cwd, env, stdin, run_id, allow=None, *, capture=False)¶
Bases:
objectDefines a commands execution request.
- cmd¶
the command to run
- cwd¶
the working directory to use
- env¶
the environment variables to use
- stdin¶
the type of standard input interaction allowed
- run_id¶
an id to identify this run
- property shell_cmd¶
The command to run as a shell command.
- property shell_cmd_redacted¶
The command with URL userinfo and secret-looking inline flag values masked.
- class tox.execute.request.StdinSource(*values)¶
Bases:
EnumWhere the standard input of a command comes from.
- OFF = 0¶
input disabled
- USER = 1¶
input via the standard input
- API = 2¶
input via programmatic access
- static user_only()¶
- Return type:
- Returns:
USERif the standard input is tty type elseOFF
- class tox.execute.api.Outcome(request, show_on_standard, exit_code, out, err, start, end, cmd, metadata, start_error=None)¶
Bases:
objectResult of a command execution.
- Variables:
OK – the exit code of a successful command
- OK = 0¶
- request¶
the execution request
- show_on_standard¶
a flag indicating if the execution was shown on stdout/stderr
- exit_code¶
the exit code for the execution
- out¶
the standard output of the execution
- err¶
the standard error of the execution
- start¶
a timer sample for the start of the execution
- end¶
a timer sample for the end of the execution
- cmd¶
the command as executed
- metadata¶
additional metadata attached to the execution
- start_error¶
the error that kept the command from starting,
Noneonce it started
- property elapsed¶
The time the execution took, in seconds.
- log_run_done(lvl)¶
Log that the run was done.
- Parameters:
lvl (
int) – the level on what to log as interpreted bylogging.log()- Return type:
- class tox.execute.api.ExecuteOptions(env)¶
Bases:
objectThe options that control how a command execution is stopped and whether its output is captured.
- Parameters:
env (
ToxEnv) – the environment the command runs in
- property suicide_timeout¶
Seconds to wait for the process to exit on its own before sending SIGINT.
- property interrupt_timeout¶
Seconds to wait after SIGINT before sending SIGTERM.
- property terminate_timeout¶
Seconds to wait after SIGTERM before sending SIGKILL.
- property no_capture¶
Whether the output is shown as it is produced, instead of only being captured.
- class tox.execute.api.Execute(colored)¶
Bases:
ABCAbstract API for execution of a tox environment.
- Parameters:
colored (
bool) – whether the output is colored
- call(request, show, out_err, env)¶
Run a request, and yield the status of the execution while it runs.
- Parameters:
request (
ExecuteRequest) – the request to runshow (
bool) – whether to show the output while the request runsout_err (
tuple[TextIOWrapper,TextIOWrapper]) – the standard output and standard error streams to write toenv (
ToxEnv) – the environment the request runs in
- Yields:
ExecuteStatus– the status of the execution
- abstractmethod build_instance(request, options, out, err)¶
Build the instance that runs a request.
- Parameters:
request (
ExecuteRequest) – the request to runoptions (
ExecuteOptions) – the options of the executionout (
SyncWrite) – the stream the standard output is written toerr (
SyncWrite) – the stream the standard error is written to
- Return type:
- Returns:
the instance that runs the request
- class tox.execute.api.ExecuteStatus(options, out, err)¶
Bases:
ABCThe state of a command execution while it runs, and its outcome once it is done.
- Parameters:
options (
ExecuteOptions) – the options of the executionout (
SyncWrite) – the stream the standard output is written toerr (
SyncWrite) – the stream the standard error is written to
- Variables:
outcome (
Outcome|None) – the outcome of the execution,Noneuntil it is done
- outcome¶
- abstract property exit_code¶
The exit code of the command,
Nonewhile it runs.
- property start_error¶
The error that kept the command from starting,
Noneonce it started.
- property out¶
The standard output collected so far.
- property err¶
The standard error collected so far.
- property metadata¶
Metadata about the execution, empty unless the executor provides some.
- abstractmethod wait(timeout=None)¶
Wait for the command to finish.
- abstractmethod write_stdin(content)¶
Write content to the standard input of the command.
- class tox.execute.api.FinishedExecuteStatus(options, out, err, exit_code)¶
Bases:
ExecuteStatusReport a fixed exit code for a command that finished or never started, without running a process.
- Parameters:
options (
ExecuteOptions) – the execution options of the commandout (
SyncWrite) – the sink for the standard outputerr (
SyncWrite) – the sink for the standard errorexit_code (
int|None) – the exit code to report,Noneif there is none
- property exit_code¶
The exit code of the command,
Nonewhile it runs.- Overrides:
- wait(timeout=None)¶
Wait for the command to finish.
- write_stdin(content)¶
Cannot write.
- Parameters:
content (
str) – the text that would be written to the standard input- Return type:
- Overrides:
- interrupt()¶
Interrupt the command.
- Return type:
- Overrides:
- class tox.execute.api.ExecuteInstance(request, options, out, err)¶
Bases:
ABCAn instance of a command execution.
- Parameters:
request (
ExecuteRequest) – the command to executeoptions (
ExecuteOptions) – the execution options of the commandout (
SyncWrite) – the sink for the standard outputerr (
SyncWrite) – the sink for the standard error
- property out_handler¶
The callback that receives the standard output of the command.
- property err_handler¶
The callback that receives the standard error of the command.
- abstract property cmd¶
The command line to run.
- class tox.execute.stream.SyncWrite(name, target, color=None)¶
Bases:
objectMake sure data collected is synced in-memory and to the target stream on every newline and time period.
Used to propagate executed commands output to the standard output/error streams visible to the user.
- Parameters:
- Variables:
REFRESH_RATE – the seconds between two syncs to the target stream
timer – the timer that syncs the content on the refresh period
- REFRESH_RATE = 0.1¶
- colored()¶
Wrap the content written inside the block in the color of the stream, when a color is set.
- Yields:
None, the block runs with the color applied
- property text¶
The collected content decoded as UTF-8, keeping the bytes that are not valid UTF-8.
- property content¶
The collected content, as raw bytes.
installer¶
- tox.tox_env.installer.InstallArguments = tox.tox_env.python.pip.req_file.PythonDeps | tox.tox_env.python.pylock.Pylock | collections.abc.Sequence[packaging.requirements.Requirement | tox.tox_env.package.Package]¶
Argument types tox itself passes to
Installer.install()and thetox_on_installhook.
- class tox.tox_env.python.pip.req.file.EnvironmentProvider(*args, **kwargs)¶
Bases:
ProtocolCallable that provides the environment variables that requirements can expand.
- class tox.tox_env.python.pip.req.file.RequirementsFile(path, constraint, environment_provider=None)¶
Bases:
objectA requirements file, with the requirements, options and constraints it declares.
- Parameters:
path (
Path) – the path of the requirements fileconstraint (
bool) – whether the file lists constraints, rather than requirementsenvironment_provider (
EnvironmentProvider|None) – the provider of the environment variables the file can expand
- class tox.tox_env.python.pip.req_file.PythonDeps(raw, root, environment_provider=None)¶
The dependencies of a tox environment, as set by its
depssetting.
- class tox.tox_env.python.pylock.Pylock(*, path, extras=frozenset({}), groups=frozenset({}), marker_env=dict())¶
Bases:
objectA
pylock.tomllock file, from which the requirements are installed.
- class tox.tox_env.installer.Installer[EnvT_co: ToxEnv, ArgsT = PythonDeps | Pylock | Sequence[Requirement | Package]](tox_env)¶
Bases:
ABC,Generic[EnvT_co,ArgsT]Install packages into a tox environment;
ArgsTis whatinstall()accepts.- Parameters:
tox_env (
EnvT_co) – the environment to install the packages into
- abstractmethod installed()¶
- abstractmethod install(arguments, section, of_type)¶
Install the given arguments in the environment.
session¶
- class tox.session.state.State(options, args)¶
Bases:
objectRuntime state holder.
- Parameters:
- Variables:
conf – the configuration of this run
- property envs¶
Access to the tox environments, selected on first access.
- class tox.session.env_select.CliEnv(value=None)¶
Bases:
objectThe user’s selection of tox test environments via
-eorenv_listconfig.It is in one of three forms:
A list of specific environments, instantiated with a string that is a comma-separated list of the environment names. (These may have spaces on either side of the commas which are removed.) As a sequence this will be a sequence of those names.
The other two forms are:
“ALL” which is all environments defined by the tox configuration. This is instantiated with
ALLeither alone or as any element of a comma-separated list; any other environment names are ignored. is_all() will be true and as a sequence it will be empty. This prints in string representation asALL.The default environments as chosen by tox configuration. This is instantiated with None as the parameter, is_default_list() will be true, and as a sequence this will be empty. This prints in string representation as
<env_list>.
- Parameters:
value (
list[str] |str|None) – the selection as given on the command line or in the configuration
- property is_all¶
Whether all environments were requested with
ALL.
- property is_default_list¶
Whether no environments were requested, so the default list applies.
- class tox.session.env_select.EnvSelector(state)¶
Bases:
objectSelect the environments of a run from the command line, the configuration and the environment.
- Parameters:
state (
State) – the state of the run- Variables:
on_empty_fallback_py – whether to fall back to the
pyenvironment when none is selected
- iter(*, only_active=True, package=False)¶
Get tox environments.
Get dict of unavailable environment names to runner names.
- ensure_only_run_env_is_active()¶
Ensure that no packaging environment is selected to run.
- Raises:
tox.report.HandledError – when a packaging environment is selected
- Return type:
testing¶
A pytest plugin useful to test tox itself (and its plugins).
- class tox.pytest.ToxProject(files, base, path, capfd, monkeypatch, mocker)¶
Bases:
objectA tox project that is created on disk for a test, from the files it is given.
- Parameters:
files (
dict[str,Any]) – the files of the project, nested by directorybase (
Path|None) – a directory to copy into the project first,Noneto copy nothingpath (
Path) – the directory of the projectcapfd (
CaptureFixture[str]) – the capture fixture of the testmonkeypatch (
MonkeyPatch) – the monkeypatch fixture of the testmocker (
MockerFixture) – the mocker fixture of the test
- property structure¶
The files of the project, nested by directory, as they are on disk.
- patch_execute(handle=None)¶
Patch the execution of the environments, so requests are handled by a function.
- run(*args, from_cwd=None, raise_on_config_fail=True)¶
Run tox in the project, with the given command line arguments.
- Parameters:
- Return type:
- Returns:
the outcome of the run
- Raises:
RuntimeError – when the run did not set an exit code
- class tox.pytest.ToxProjectCreator(*args, **kwargs)¶
Bases:
ProtocolCallable that creates a tox project for a test, from its files.
- class tox.pytest.ToxRunOutcome(cmd, cwd, code, out, err, state)¶
Bases:
objectThe outcome of running tox in a test project.
- Parameters:
cmd (
Sequence[str]) – the command line arguments tox was run withcwd (
Path) – the directory tox was run incode (
int) – the exit code of the runout (
str) – the standard output of the runerr (
str) – the standard error of the runstate (
State|None) – the state of the run,Nonewhen it was not captured
- property shell_cmd¶
The command line tox was run with, as a string a shell runs.
- env_conf(name)¶
Get the configuration of an environment of the run.
- Parameters:
name (
str) – the name of the environment- Return type:
- Returns:
the configuration of the environment
- property state¶
The state of the run, which is not available when it was not captured.
- Raises:
RuntimeError – when the state was not captured
- property success¶
Whether the run succeeded.
- assert_failed(code=None)¶
Assert that the run failed.
- assert_out_err(out, err, *, dedent=True, regex=False)¶
Assert the standard output and standard error of the run.