Settings¶
Every Hegel run is configured by a hegel.Settings value. This page
covers what the settings are, the places each one can be set, how those places
combine, and how the profile a run starts from is chosen.
The settings¶
Setting |
Values |
Base value |
Effect |
|---|---|---|---|
|
integer ≥ 0 |
|
How many test cases to run. |
|
|
|
How much Hegel prints ( |
|
integer, or |
|
A fixed seed, for reproducibility. |
|
boolean |
|
Use a fixed seed derived from the test, so every run of a test is the same. A fixed |
|
a directory path, |
|
Where failing examples are kept for replay. |
|
collection of |
none |
Health checks that should not fail the run. See Suppress a health check. |
|
collection of |
all five |
Which parts of the run happen; leaving out |
|
boolean |
|
Report every distinct failure a run finds, as a |
|
boolean |
|
Stop generating once a failure is found. When |
|
boolean |
|
Print the end-of-run statistics report for events recorded with |
|
boolean |
|
Let a test case make any number of choices. Otherwise a test case making more than 220 choices is stopped and discarded. A long-running test case, such as a concurrent state machine driven for hours, needs the limit removed; the cost is the memory to record every choice. Suppressing the |
|
boolean |
|
On failure, print a |
|
|
|
The source of randomness ( |
|
|
|
How a run reacts when the test behaves nondeterministically ( |
In Python, a setting whose value is an enum takes either the member
(Verbosity.verbose) or its name ("verbose"), and one taking a collection of
enum members also accepts a single one. The names are also the vocabulary of
hegel.toml.
Where settings come from¶
A run’s settings are built in layers. Each layer overrides what the layers below it set and leaves the rest alone:
The base settings: the values in the table above. They cannot be changed, and are available by name as the reserved
baseprofile.The profile: a named set of overrides, from the profiles shipped with Hegel, your
hegel.toml, and profiles registered in Python.Settings()resolves thedefaultprofile, the one in effect for the current environment;Settings.from_profileresolves any profile by name. Most of the rest of this page is about this layer.Environment variables, applied over the resolved profile:
Variable
Effect
HEGEL_TEST_CASESSets
test_cases. Must be a positive integer.HEGEL_DATABASESets
database:disabledturns it off, any other value is the path.HEGEL_STATISTICSAnything but
0or the empty string turnsshow_statisticson.HEGEL_SEEDSets
seed: an integer is the seed,noneclears one the profile set.HEGEL_DERANDOMIZESets
derandomize:true,1oryes, orfalse,0orno.HEGEL_PRINT_BLOBSets
print_blob, with the same vocabulary.HEGEL_STOP_ON_FIRST_FAILURESets
stop_on_first_failure, with the same vocabulary.HEGEL_UNBOUNDED_CHOICESSets
unbounded_choices, with the same vocabulary.HEGEL_NONDETERMINISM_STRICTNESSSets
nondeterminism_strictness:quiet,warnorerror.HEGEL_VERBOSITYSets
verbosity:quiet,normal,verboseordebug.HEGEL_PHASESSets
phases: comma-separated phase names, such asgenerate,shrink.HEGEL_SUPPRESS_HEALTH_CHECKSets
suppress_health_check: comma-separated health check names, orall.HEGEL_REPORT_MULTIPLE_FAILURESSets
report_multiple_failures, with the boolean vocabulary.HEGEL_BACKENDSets
backend:defaultorurandom.An empty variable is ignored; any other malformed value is an error, raised when a
Settingsvalue is created. A fixedseed, wherever it came from, still takes precedence overderandomize, soHEGEL_DERANDOMIZE=truehas no effect on a profile with a seed unlessHEGEL_SEED=noneclears it.Settings in the test: the keyword arguments of
@hegel.test, applied over thesettings=argument if one is given, or overSettings()otherwise:@hegel.test(test_cases=500, derandomize=True) def test_compiled_in(tc): ...
These are the settings the author of the test chose, so they take precedence over the environment variables: a variable adjusts a test suite, not a test that sets the same setting itself. A
Settingsobject passed assettings=belongs to this layer too: every field it holds, the ones it was given and the ones it copied from the layers below when it was made, is set for the run.
A Settings object resolves the layers below it once, when it is created, and
keeps a copy of every field. Changes to the environment or the default profile
made later do not reach it, so a Settings object made at import time, in a
conftest.py say, keeps the values it was made with. Keyword arguments to
@hegel.test are different: they are resolved over the default profile each
time the test runs, so they follow such changes.
HEGEL_DEFAULT_PROFILE and HEGEL_CONFIG also come from the environment, but
act on the second layer, choosing the default profile and the configuration
file. The pytest options act on it too.
For example, with this hegel.toml:
[profiles.ci]
test_cases = 1000
a test declared @hegel.test and run on a CI server with
HEGEL_TEST_CASES=5000 resolves the ci profile (1000 test cases,
derandomized, database off) and the environment variable overrides
test_cases to 5000. A test declared @hegel.test(test_cases=200) in the same
run keeps its 200. Locally, without the variable, the first test runs 100 test
cases and the second 200, with the development profile’s settings for
everything else.
Profiles¶
A profile is a named set of changes to another profile: the settings it overrides, plus the profile it extends. Resolving a profile follows that chain down to the base settings and applies the changes from the bottom up.
The reserved names¶
baseis the base settings from the table above. It ends every chain, so a profile that extendsbase, or a test that selects it, gets exactly the base settings plus its own overrides, whichever profile the environment would otherwise have chosen. (TheHEGEL_*settings variables still apply over it, as over every profile.)defaultis the default profile: the one a run gets when nothing names a profile, and the one custom profiles extend when they don’t say otherwise. It is an alias, resolved as described under Choosing the default profile.
Neither can be modified or registered.
The shipped profiles¶
Three profiles ship with Hegel. All three extend base directly.
Profile |
Overrides |
When it is the environment’s profile |
|---|---|---|
|
nothing |
Locally: whenever neither of the others applies. |
|
|
On a CI server, detected from |
|
|
Inside Antithesis, detected from |
Custom profiles and inheritance¶
Custom profiles are defined in hegel.toml or registered in Python. A
hegel.toml profile chooses its parent with extends. Without one, a custom
profile extends default, and a shipped profile extends base. So with
[profiles.nightly]
test_cases = 10000
[profiles.pinned]
extends = "base"
test_cases = 10000
[profiles.deep-ci]
extends = "ci"
test_cases = 100000
nightlyresolves asnightly→ci→baseon a CI server andnightly→development→baselocally: it gets the environment’s behaviour plus more test cases, wherever it is selected.pinnedresolves aspinned→baseeverywhere: 10000 test cases, a fresh seed and the database on, even on CI (unless aHEGEL_*variable says otherwise).deep-ciresolves asdeep-ci→ci→baseeverywhere.
Because the shipped profiles are siblings, a change meant for every
environment does not go in development; it goes in a profile of its own,
which extends base and which the others name with extends:
[profiles.common]
extends = "base"
test_cases = 200
[profiles.development]
extends = "common"
[profiles.ci]
extends = "common"
A hegel.toml section for a shipped profile merges over the shipped
settings ([profiles.ci] with print_blob = false keeps derandomization and
the disabled database), and may set extends to change its parent, as above.
common has to extend base explicitly. Without that it would extend
default, which is development locally, and development extends common:
a cycle. An extends naming an unknown profile, or a cycle, is an error.
Every profile in a hegel.toml is checked whenever any profile is resolved,
so a broken profile fails loudly even before something selects it.
Choosing the default profile¶
The default alias resolves to the first of these that is set:
Settings.set_default_profile, which the--hegel-*pytest options use.The
HEGEL_DEFAULT_PROFILEenvironment variable, when non-empty.The top-level
default = "<profile>"entry inhegel.toml.The environment’s profile:
workloadinside Antithesis, elsecion a CI server, elsedevelopment.
Naming a profile that does not exist is an error, reported with the list of known profiles.
HEGEL_DEFAULT_PROFILE=nightly pytest
Selecting a profile for one test¶
Settings.from_profile resolves a profile
by name without changing what default is:
@hegel.test(settings=hegel.Settings.from_profile("nightly"))
def test_thorough(tc): ...
The selected profile still sits on its usual parent, so nightly selected this
way on CI still inherits from ci.
hegel.toml¶
Discovery¶
Hegel looks for hegel.toml in the working directory of the test process and
then in each of its parent directories; the first file found is used, and
files are never merged. The file is read once per process.
To load a file somewhere else, set HEGEL_CONFIG to its path. A non-empty
HEGEL_CONFIG that cannot be read is an error.
Format¶
The file has an optional top-level default = "<profile>" entry and
[profiles.<name>] tables whose entries are settings. Hegel is strict about
the contents: an unknown key, a value of the wrong type, or any other
top-level key is an error naming the file and line, as is malformed TOML.
Profile names use ASCII letters, digits, - and _, and base and default
cannot be sections.
default = "nightly" # optional: the default profile for this project
[profiles.development]
test_cases = 200
[profiles.ci] # merges onto the shipped ci profile
test_cases = 1000
print_blob = false
[profiles.nightly]
extends = "ci"
test_cases = 10000
seed = "none"
suppress_health_check = ["too_slow", "filter_too_much"]
phases = ["explicit", "reuse", "generate", "target", "shrink"]
database = "default"
backend = "default"
Every setting in the table at the top of this page is accepted, plus
extends. Two values exist to undo a parent’s setting: seed = "none" clears
an inherited seed, and database = "default" restores the default database
after a parent turned it off or set a path. In hegel.toml,
database = "disabled" turns the database off, and
suppress_health_check = ["all"] suppresses every health check.
Profiles in Python¶
Settings.register_profile resolves a
Settings value and stores the result, a complete snapshot of every setting,
under a name, for the rest of the process:
hegel.Settings.register_profile(
"nightly", hegel.Settings.from_profile("ci"), test_cases=10_000
)
A registered profile ends its chain, like base: it has no parent, because
the snapshot already holds every setting. Registering a shipped profile’s name
replaces that profile completely. A hegel.toml section of the same name
still merges over the snapshot. Registering again under the same name replaces
the earlier snapshot.
Settings.set_default_profile makes
a profile the default for the process. The profile must already exist.
Neither call is retroactive: a Settings value created before them keeps its
fields. Make them before the settings that should see them are made: in a
conftest.py, for example, before any Settings(...) value, while a test
declared @hegel.test(test_cases=500) resolves its profile each time it runs
and so sees them whenever they are made before it runs.
Environment variables¶
Variable |
Effect |
|---|---|
|
The default profile, unless |
|
The path of the |
|
Sets |
|
Sets |
|
Turns |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Sets |
|
Selects the |
|
Selects the |