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 show-configPrint the resolved configuration karva would run with
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.--cov-branchMeasure branch coverage in addition to line coverage
--cov-contextcontextRecord per-test coverage contexts.
Currently supports
test, which records the qualified test name for each line executed while that test is running. Contexts are emitted in JSON coverage reports.Possible values:
test: Record the current test name for each covered line
--cov-fail-underpercentFail the run if total coverage is below the given percentage.
Accepts any value in
0..=100(fractional values such as90.5are allowed). When the reportedTOTALpercentage is below the threshold, the test command exits with a non-zero status even if every test passed. Has no effect when tests have already failed.--cov-includeglobInclude only coverage report files whose project-relative path matches this glob.
May be passed multiple times.
--cov-omitglobExclude coverage report files whose project-relative path matches this glob.
May be passed multiple times.
--cov-reporttypeCoverage report type.
term(default) prints a compact terminal table.term-missingextends it with aMissingcolumn listing the uncovered line numbers per file.xml[:PATH],json[:PATH], andhtml[:DIR]write reports to disk.--durationsnShow the N slowest tests after the run completes
--fail-fastfail-fastStop scheduling new tests after the first failure.
Equivalent to
--max-fail=1. Use--no-fail-fastto keep running after failures.Possible values:
truefalse
--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-cacheno-cacheDisable reading the karva cache for test duration history
Possible values:
truefalse
--no-captureDisable output capture and run tests serially.
Lets stdout/stderr from tests flow directly to the terminal, useful when debugging with print statements or interactive debuggers. Implies
--show-outputand forces a single worker so output from concurrent tests cannot interleave.--no-covDisable coverage measurement for this run.
Overrides any
--covflag and any[coverage] sourcesconfigured inkarva.toml/pyproject.toml. Useful when iterating locally without editing config.--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-ignoreno-ignoreWhen set, .gitignore files will not be respected
Possible values:
truefalse
--no-parallelno-parallelDisable parallel execution (equivalent to
--num-workers 1)Possible values:
truefalse
--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
--partitionstrategy:m/nRun only one partition of the collected tests.
Accepts
slice:M/Nwhere this run executes sliceMofNtotal slices (1-indexed). Tests are sorted by qualified name and then distributed by cycling through slices: test 1 to slice 1, test 2 to slice 2, ..., test N+1 to slice 1, and so on. Running everyslice:1/Nthroughslice:N/Ntogether covers every collected test exactly once.Also accepts
hash:M/N, which assigns each test to a stable bucket based on its qualified name. Hash partitioning is less balanced thanslice, but adding or removing a test only changes that test's bucket.--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.--result-formatformatMachine-readable test result format
Possible values:
json: Write one JSON document with the full run resultjsonl: Write newline-delimited JSON events
--result-outputpathWrite machine-readable test results to this path
--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
--run-timeoutsecondsWall-clock limit for the whole run, in seconds.
When the run takes longer than this duration, karva stops the remaining workers and exits with a failure status. Accepts fractional seconds such as
--run-timeout=1800or--run-timeout=0.5.--show-output,-sshow-outputShow Python stdout during test execution
Possible values:
truefalse
--slow-timeoutsecondsThreshold in seconds after which a test is flagged as slow.
When a test takes longer than this duration, it is reported with a
SLOWstatus line (gated on--status-level=slowor higher) and counted in the run summary. Pass a positive number such as--slow-timeout=60or--slow-timeout=0.5.--snapshot-updatesnapshot-updateUpdate snapshots directly instead of creating pending
.snap.newfiles.When set,
karva.assert_snapshot()will write directly to.snapfiles, accepting any changes automatically.Possible values:
truefalse
--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
--termination-grace-periodsecondsGrace period before force-killing workers during shutdown, in seconds.
When karva stops workers because of Ctrl+C, fail-fast, or
--run-timeout, it first asks them to terminate gracefully. If they are still running after this period, karva force-kills them. Pass0to force-kill immediately after graceful termination.--test-prefixtest-prefixThe prefix of the test functions
--timeoutsecondsHard per-test timeout, in seconds.
Tests that run longer than this duration are killed and reported as failures. A test-level [
@karva.tags.timeout] decorator overrides the default for that specific test.Accepts fractional seconds such as
--timeout=120or--timeout=0.5.--try-import-fixturestry-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.
Possible values:
truefalse
--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 show-config
Print the resolved configuration karva would run with
Usage
| Text Only | |
|---|---|
1 | |
Options
--config-filepathThe path to a
karva.tomlfile to use for configurationMay also be set with the
KARVA_CONFIG_FILEenvironment variable.--help,-hPrint help (see a summary with '-h')
--profile,-PnameConfiguration profile to resolve.
Defaults to
default.May also be set with the
KARVA_PROFILEenvironment variable.
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 | |