CLI Reference
karva
A Python test runner.
Usage
| Text Only | |
|---|---|
1 | |
Commands
karva testRun tests
karva snapshotManage snapshots created by
karva.assert_snapshot()karva cacheManage the karva cache
karva versionDisplay Karva's version
karva helpPrint this message or the help of the given subcommand(s)
karva test
Run tests
Usage
| Text Only | |
|---|---|
1 | |
Arguments
PATHSList of files, directories, or test functions to test [default: the project root]
Options
--colorcolorControl when colored output is used
Possible values:
auto: Display colors if the output goes to an interactive terminalalways: Always display colorsnever: Never display colors
--config-filepathThe path to a
karva.tomlfile to use for configuration.While karva configuration can be included in a
pyproject.tomlfile, it is not allowed in this context.May also be set with the
KARVA_CONFIG_FILEenvironment variable.--covsourceMeasure code coverage for the given source path.
May be passed multiple times to measure several sources. Pass without a value (
--cov) to measure the current working directory.--durationsnShow the N slowest tests after the run completes
--fail-fastStop scheduling new tests after the first failure.
Equivalent to
--max-fail=1. Use--no-fail-fastto keep running after failures.--filter,-Efilter-expressionsFilter tests using a filterset expression.
Predicates:
test(<matcher>)matches the fully qualified test name;tag(<matcher>)matches any custom tag on the test.Matchers:
=exact,~substring,/regex/,#glob. The default is substring fortest()and exact fortag(). String bodies may be quoted ("...") to allow spaces or reserved characters.Operators:
&/and,|/or,not/!, and-as shorthand for "and not". Use parentheses for grouping.andbinds tighter thanor.When specified multiple times, a test runs if it matches any of the expressions (OR semantics across flags).
Examples:
-E 'tag(slow)',-E 'test(/^mod::test_login$/)',-E 'tag(slow) & test(~login)',-E '(tag(fast) | tag(unit)) - tag(flaky)'.--final-status-levellevelTest summary information to display at the end of the run [default: pass]
May also be set with the
KARVA_FINAL_STATUS_LEVELenvironment variable.Possible values:
none: Don't display the summary line or any diagnostic blocksfail: Only display the summary line and diagnostics on failureretry: Display the summary line plus diagnostics on failure or when any test was retried. The summary line gains aN retriedcount whenever a retry happenedslow: Same asretryuntil a slow-test threshold is implementedpass: Always display the summary line and diagnostics (default)skip: Same aspassuntil skip-specific summary lines are emittedall: Always display every summary status
--help,-hPrint help (see a summary with '-h')
--last-failed,--lfRe-run only the tests that failed in the previous run
--max-failnStop scheduling new tests after this many failures.
Accepts a positive integer such as
--max-fail=3.--max-fail=1is equivalent to the legacy--fail-fast, and--no-fail-fastclears the limit. When--max-failis provided alongside--fail-fastor--no-fail-fast,--max-failtakes precedence.--no-cacheDisable reading the karva cache for test duration history
--no-fail-fastRun every test regardless of how many fail.
Clears any
fail-fastormax-failvalue set in configuration. When--max-failis provided alongside--no-fail-fast,--max-failtakes precedence.--no-ignoreWhen set, .gitignore files will not be respected
--no-parallelDisable parallel execution (equivalent to
--num-workers 1)--no-testsactionBehavior when no tests are found to run [default: auto]
May also be set with the
KARVA_NO_TESTSenvironment variable.Possible values:
auto: Automatically determine behavior: fail if no filter expressions were given, pass silently if filters were givenpass: Silently exit with code 0warn: Produce a warning and exit with code 0fail: Produce an error message and exit with a non-zero code
--num-workers,-nnum-workersNumber of parallel workers (default: number of CPU cores)
--output-formatoutput-formatThe format to use for printing diagnostic messages
Possible values:
full: Print diagnostics verbosely, with context and helpful hints (default)concise: Print diagnostics concisely, one per line
--profile,-PnameConfiguration profile to use.
Profiles are defined as
[profile.<name>]sections inkarva.toml(or[tool.karva.profile.<name>]inpyproject.toml) and may override any of the[src],[terminal], and[test]settings. The selected profile is layered on top of any[profile.default]overrides, which themselves layer on top of the top-level options.Defaults to
default.May also be set with the
KARVA_PROFILEenvironment variable.--retryretryWhen set, the test will retry failed tests up to this number of times
--run-ignoredrun-ignoredRun ignored tests
Possible values:
only: Run only ignored testsall: Run both ignored and non-ignored tests
--show-output,-sShow Python stdout during test execution
--snapshot-updateUpdate snapshots directly instead of creating pending
.snap.newfiles.When set,
karva.assert_snapshot()will write directly to.snapfiles, accepting any changes automatically.--status-levellevelTest result statuses to display during the run [default: pass]
May also be set with the
KARVA_STATUS_LEVELenvironment variable.Possible values:
none: Don't display any test result lines (or the "Starting" header)fail: Only display failed test resultsretry: Display failed test results plus aTRY N FAILline for each failed attempt that was retriedslow: Display failed, retried, and slow test results. Karva does not yet have a slow-test threshold, so this currently behaves likeretrypass: Display failed, retried, slow, and passing test results (default)skip: Additionally display skipped test resultsall: Display all test result statuses
--test-prefixtest-prefixThe prefix of the test functions
--try-import-fixturesWhen set, we will try to import functions in each test file as well as parsing the ast to find them.
This is often slower, so it is not recommended for most projects.
--verbose,-vUse verbose output (or
-vvand-vvvfor more verbose output)--watchRe-run tests when Python source files change
karva snapshot
Manage snapshots created by karva.assert_snapshot()
Usage
| Text Only | |
|---|---|
1 | |
Commands
karva snapshot acceptAccept all (or filtered) pending snapshots
karva snapshot rejectReject all (or filtered) pending snapshots
karva snapshot pendingList pending snapshots
karva snapshot reviewInteractively review pending snapshots
karva snapshot pruneRemove snapshot files whose source test no longer exists
karva snapshot deleteDelete all (or filtered) snapshot files (.snap and .snap.new)
karva snapshot helpPrint this message or the help of the given subcommand(s)
karva snapshot accept
Accept all (or filtered) pending snapshots
Usage
| Text Only | |
|---|---|
1 | |
Arguments
PATHSOptional paths to filter snapshots by directory or file
Options
--help,-hPrint help
karva snapshot reject
Reject all (or filtered) pending snapshots
Usage
| Text Only | |
|---|---|
1 | |
Arguments
PATHSOptional paths to filter snapshots by directory or file
Options
--help,-hPrint help
karva snapshot pending
List pending snapshots
Usage
| Text Only | |
|---|---|
1 | |
Arguments
PATHSOptional paths to filter snapshots by directory or file
Options
--help,-hPrint help
karva snapshot review
Interactively review pending snapshots
Usage
| Text Only | |
|---|---|
1 | |
Arguments
PATHSOptional paths to filter snapshots by directory or file
Options
--help,-hPrint help
karva snapshot prune
Remove snapshot files whose source test no longer exists
Usage
| Text Only | |
|---|---|
1 | |
Arguments
PATHSOptional paths to filter snapshots by directory or file
Options
karva snapshot delete
Delete all (or filtered) snapshot files (.snap and .snap.new)
Usage
| Text Only | |
|---|---|
1 | |
Arguments
PATHSOptional paths to filter which snapshot files are deleted
Options
karva snapshot help
Print this message or the help of the given subcommand(s)
Usage
| Text Only | |
|---|---|
1 | |
karva cache
Manage the karva cache
Usage
| Text Only | |
|---|---|
1 | |
Commands
karva cache pruneRemove all but the most recent test run from the cache
karva cache cleanRemove the entire cache directory
karva cache helpPrint this message or the help of the given subcommand(s)
karva cache prune
Remove all but the most recent test run from the cache
Usage
| Text Only | |
|---|---|
1 | |
Options
--help,-hPrint help
karva cache clean
Remove the entire cache directory
Usage
| Text Only | |
|---|---|
1 | |
Options
--help,-hPrint help
karva cache help
Print this message or the help of the given subcommand(s)
Usage
| Text Only | |
|---|---|
1 | |
karva version
Display Karva's version
Usage
| Text Only | |
|---|---|
1 | |
Options
--help,-hPrint help
karva help
Print this message or the help of the given subcommand(s)
Usage
| Text Only | |
|---|---|
1 | |