pytest integration¶
Installing Hegel registers a pytest plugin, so Hegel
tests run under pytest without any configuration. A function decorated with
@hegel.test is an ordinary test function to pytest: its
parameters after the test case are pytest fixtures, and it can be
parametrised and marked like any other test.
Markers¶
The plugin marks every Hegel test with the hegel marker, so you can select
or deselect them:
pytest -m hegel # only Hegel tests
pytest -m "not hegel" # everything else
Command-line options¶
These options change the settings of every Hegel test in the run:
--hegel-profile NAMEStart from the named settings profile, instead of the default one.
--hegel-setting KEY=VALUESet any setting, named by its
hegel.tomlkey, with the value spelled as inhegel.toml(see Settings):--hegel-setting test_cases=1000,--hegel-setting suppress_health_check=too_slow,filter_too_much,--hegel-setting unbounded_choices=true. Booleans taketrue,1,yes,false,0orno, and lists their names separated by commas. Repeat the option to set several. Hegel’s engine parses the values, so they read the same as inhegel.tomland theHEGEL_*environment variables, and an unknown key or value is a usage error that lists what is accepted.--hegel-seed SEEDFix the seed: an integer from 0 to 264 - 1, or
nonefor a fresh random seed.--hegel-verbosity {quiet,normal,verbose,debug}Set the verbosity.
--hegel-derandomizeDerive each test’s seed from the test itself, so that every run of a test generates the same test cases.
--hegel-database PATHKeep the example database in
PATH.--hegel-database=(empty) or--hegel-database=disabledturns the database off, and--hegel-database=defaultselects the default directory, as inhegel.toml; write./defaultfor a directory of that name.
The options act on the default profile: Hegel builds a profile from the one
named by --hegel-profile (or the default profile) with the other options
applied, the --hegel-setting options first and then the others, and makes it
the default for the run. So settings written in a test, or given to a
Settings object, still take precedence over the options, and so
do the HEGEL_* environment variables in Settings, which apply on top of
whichever profile is the default. A Settings object resolves its profile when
it is created, so one created at import time, in a conftest.py loaded before
the options are applied, say, does not see them; the keyword arguments of
@hegel.test are resolved when the test runs and do.
Detecting Hegel tests¶
A function decorated with @hegel.test has an is_hegel_test attribute set
to True, and the undecorated function as hegel_inner_test.