Skip to content

pytest options

A plain pytest run writes no report. Each --given-* output flag turns on one report format, and you can combine them. For example, pass both --given-json and --given-html to get both files from one run.

The checks, however, always run. Every run builds the report, even if it doesn't write it. So a step that can't be reported correctly, like one that breaks the parametrize rules, fails every run, not just the first run that writes a report.

Flags

Flag Default Description
--given-json[=PATH] off Write the JSON report data. Without a path: given-report/report-data.json.
--given-html[=PATH] off Write the HTML report. Without a path: given-report/report.html.
--given-md[=PATH] off Write the Markdown report. Without a path, it prints to stdout, between <!-- pytest-given:md:start --> and <!-- pytest-given:md:end --> markers.
--given-md-lines / --no-given-md-lines true Show the line in the file.py:line::test_name anchor under each Markdown heading. Off, the anchor is the node ID, so a Markdown diff doesn't show every anchor below an inserted test. Ini setting: given_md_lines; both flags override it.
--given-md-source off End each Markdown scenario with its test function, decorators included, each line under its number in the file, for reviewing step text against step body. Only the test function is shown, not the step fixtures or helpers it uses. No ini setting.
--given-title=TEXT rootdir name The report's name: the Markdown heading, and the HTML report's browser tab title and top bar. Ini setting: given_title.
--given-report-url=URL unset The public URL the HTML report will be served from, such as its page on your docs site. The report then shows copy buttons that put a Markdown citation linking there on the clipboard, and pytest-given citations checks links to it. Ini setting: given_report_url.
--given-source-link=PRESET none An editor preset (vscode, cursor, zed, pycharm, github) or a URL template. HTML only. Adds a clickable file:line link to each scenario card, story panel, and expanded glossary term. Ini setting: given_source_link. See Source links.
--given-all-frames off Keep pytest's and pytest-given's internal frames (pluggy, _pytest, pytest-given) in failure tracebacks. See Traceback frames.
--given-lint / --no-given-lint false Turn the narration lint on or off. A lint finding with severity error fails the run. Ini setting: given_lint; both flags override it. See Narration lint.
--given-theme=light\|dark\|auto auto The theme the HTML report opens in. auto follows the viewer's system setting. The report's own Light / Dark / System switch overrides it in each browser. Ini setting: given_theme.

Flag order

If an output flag has no =PATH, pytest reads the next word on the command line as its path, not as a test to run. To avoid this, either:

  • put --given-json, --given-html or --given-md last on the command line, or
  • use the =PATH form: --given-html=out.html, not --given-html out.html.

If that path can't be a report file, like a .py test file, pytest-given stops before running the tests, so it never overwrites your test.

Selecting scenarios

pytest-given marks every @scenario test, each case of a parametrized one included, with the pytest_given marker. You don't apply it yourself: a hand-written @pytest.mark.pytest_given on a plain test makes it selectable, but records nothing. The marker is registered, so --strict-markers accepts it. Select with pytest's own -m:

  • A report without running the plain tests. The report holds only scenarios, so pytest -m pytest_given --given-html writes the same report as a full run, faster.
  • Code coverage of the scenarios. pytest -m pytest_given --cov=mypkg (with pytest-cov), or coverage run -m pytest -m pytest_given. It counts the lines the scenarios run, not the lines a step describes, so it is an upper bound on what the report documents. Compare it with a full run's coverage: lines the suite covers but the scenarios don't are behavior only plain tests reach, and the report doesn't show.
  • The plain tests alone, with pytest -m "not pytest_given".

A -m on the command line replaces one in your addopts, so combine them yourself: -m "pytest_given and not slow". In a suite with no scenarios, -m pytest_given deselects every test and pytest exits with code 5.

Mind -k: it matches any part of a test's keywords, and a scenario's include pytest_given and _scenario, so -k given or -k scenario selects every scenario too.

pytest-xdist

pytest-given can't write a report or lint under pytest-xdist. With -n, tests run in worker processes, and their steps never reach the main process. So a -n run that asks for a report (--given-json, --given-html, --given-md) or the narration lint (--given-lint, or given_lint = true) stops with a usage error before it collects. Generate reports and lint from a run without -n, or with -n 0. A -n run that asks for neither runs as usual. Pass --no-given-lint to one in a project that turns the lint on in its ini.

Ini settings

Put ini settings in [tool.pytest] in pyproject.toml (pytest 9's native TOML table). pytest still reads the older [tool.pytest.ini_options], but you can't use both: pytest raises UsageError if both are present.