# Python : Testing : pytest : Options ## CLI Options Not including startup & test-discovery options which are covered in [[Tech/Python/Testing/pytest/Overview|Overview]]. ``` -h | --help ## Behavior --collect-only # see results of test collection without running tests --setup-plan # show what fixtures and tests would be executed but don't execute anything -x | --exitfirst # exit on first error or failure --maxfail=N # exit after N failures --strict-config # exit if any issues with config file --strict-markers # warn of unregistered markers --pdb # drop to debugger on test fail # exception info stored in: sys.last_value + sys.last_type + sys.last_traceback ## Output --color= # yes | no | auto -q | --quiet # repeatable (-qq) -v | --verbose # repeatable (-vv) --log-level= # int or name ("INFO") --log-cli-level= # int or name ("INFO) --capture= # output capture method # fd -> capture at file descriptor level (default) # sys -> capture at the sys level # no -> don't capture (shortcut: -s) # tee-sys -> capture to logs but also output to sys level streams --tb= # traceback print mode # auto -> long for first/last entry but short for other (default) # long -> exhaustive, informative traceback formatting # short -> shorter traceback format # line -> only one line per failure # native -> Python standard library formatting # no -> no traceback at all --show-capture= # how captured stdout/stderr/log is shown on failed tests # no | stdout | stderr | log | all (default) ``` ## Config Options Multiple values can be specified as list of strings or string of space-separated values: ```toml markers = "foo bar" markers = [ "foo", "bar" ] ``` ```toml console_output_style = "progress" # classic -> classic # progress -> classic + progress indicator # progress-even-when-capture-no -> like progress, but progress indicator remains when capture=no # count -> like progress, but shown as number of tests instead of percent log_cli = False # enable log display during test run log_cli_level = ? # integer or name (ex: "INFO") log_level = ? # integer or name (ex: "INFO") markers = "m1 ..." # register custom markers = { "m1": "desc", ... } # must be limited to a single line python_classes = "Test*" # one or more prefixes or glob-style patterns python_files = "test_*.py *_test.py" # one or more prefixes or glob-style patterns python_functions = "test*" # one or more prefixes or glob-style patterns pythonpath = None # directories (rel to rootdir) to prepend to sys.path testpaths = None # directories that should be searched for tests norecursedirs = None # fnmatch-style patterns of dirs to skip # default: *.egg, .*, _darcs, build, CVS, dist, node_modules, venv, {arch} # setting this option replaces the default usefixtures = None # fixtures to apply to all functions; equiv to applying # @pytest.mark.usefixtures( ... ) to all test functions ``` ## pytestconfig Fixture Provides an instance of `pytest.Config`. ```python .rootpath # /home/ofer/src .inipath # /home/ofer/src/pyproject.toml .option # argparse.Namespace instance containing CLI options as attributes .invocation_params # pytest.Config.InvocationParams instance containing CLI params as attributes .getini( name ) # returns value from config file .getoption( name ) # returns value from CLI options .get_verbosity() ``` ```python pytest.Config.InvocationParams( args = () plugins = None dir = PosixPath( '/home/ofer/src' ) ) ``` ```python argparse.Namespace( assertmode = 'rewrite' basetemp = None cacheclear = False cacheshow = None capture = 'fd' -> 'no' # --capture=no code_highlight = 'yes' collect_in_virtualenv = False collectonly = False color = 'auto' confcutdir = None continue_on_collection_errors = False debug = None deselect = None disable_warnings = False doctest_continue_on_failure = False doctest_ignore_import_errors = False doctestglob = [] doctestmodules = False doctestreport = 'udiff' durations = None durations_min = 0.005 failedfirst = False file_or_dir = [] fold_skipped = True fulltrace = False help = False ignore = None ignore_glob = None importmode = 'prepend' -> 'importlib' # --import-mode=importlib inifilename = None junitprefix = None keepduplicates = False keyword = '' last_failed_no_failures = 'all' lf = False log_auto_indent = None log_cli_date_format = None log_cli_format = None log_cli_level = None log_date_format = None log_file = None log_file_date_format = None log_file_format = None log_file_level = None log_file_mode = None log_format = None log_level = None logger_disable = [] markers = False markexpr = '' maxfail = 0 newfirst = False no_header = False no_summary = False noconftest = False override_ini = None pastebin = None plugins = [] pyargs = False pythonwarnings = None reportchars = 'fE' rootdir = None runxfail = False setuponly = False setupplan = False setupshow = False show_fixtures_per_test = False showcapture = 'all' showfixtures = False showlocals = False -> True # --showlocals stepwise = False stepwise_skip = False strict = False strict_config = False strict_markers = False -> True # --strict-markers tbstyle = 'auto' trace = False traceconfig = False usepdb = False usepdb_cls = None verbose = 0 -> 2 # -vv version = 0 xfail_tb = False xmlpath = None ) ```