_pytest.config.argparsing module¶
-
class
Parser
(usage: Optional[str] = None, processopt: Optional[Callable[[Argument], None]] = None)[source]¶ Bases:
object
Parser for command line arguments and ini-file values.
- Variables
extra_info – dict of generic param -> value to display in case there’s an error processing the command line arguments.
-
processoption
(option: _pytest.config.argparsing.Argument) → None[source]¶
-
getgroup
(name: str, description: str = '', after: Optional[str] = None) → _pytest.config.argparsing.OptionGroup[source]¶ get (or create) a named option Group.
- Name
name of the option group.
- Description
long description for –help output.
- After
name of other group, used for ordering –help output.
The returned group object has an
addoption
method with the same signature asparser.addoption
but will be shown in the respective group in the output ofpytest. --help
.
-
addoption
(*opts: str, **attrs: Any) → None[source]¶ register a command line option.
- Opts
option names, can be short or long options.
- Attrs
same attributes which the
add_argument()
function of the argparse library accepts.
After command line parsing options are available on the pytest config object via
config.option.NAME
whereNAME
is usually set by passing adest
attribute, for exampleaddoption("--long", dest="NAME", ...)
.
-
parse
(args: Sequence[Union[str, py._path.local.LocalPath]], namespace: Optional[argparse.Namespace] = None) → argparse.Namespace[source]¶
-
_getparser
() → _pytest.config.argparsing.MyOptionParser[source]¶
-
_preprocess_options_for_no_prefix
(groups: List[OptionGroup]) → None[source]¶ Add “–no-“-prefixed option names for “store_true” actions.
-
parse_setoption
(args: Sequence[Union[str, py._path.local.LocalPath]], option: argparse.Namespace, namespace: Optional[argparse.Namespace] = None) → List[str][source]¶
-
parse_known_args
(args: Sequence[Union[str, py._path.local.LocalPath]], namespace: Optional[argparse.Namespace] = None) → argparse.Namespace[source]¶ parses and returns a namespace object with known arguments at this point.
-
parse_known_and_unknown_args
(args: Sequence[Union[str, py._path.local.LocalPath]], namespace: Optional[argparse.Namespace] = None) → Tuple[argparse.Namespace, List[str]][source]¶ parses and returns a namespace object with known arguments, and the remaining arguments unknown at this point.
-
exception
ArgumentError
(msg: str, option: Union[Argument, str])[source]¶ Bases:
Exception
Raised if an Argument instance is created with invalid or inconsistent arguments.
-
class
Argument
(*names: str, **attrs: Any)[source]¶ Bases:
object
class that mimics the necessary behaviour of optparse.Option
it’s currently a least effort implementation and ignoring choices and integer prefixes https://docs.python.org/3/library/optparse.html#optparse-standard-option-types
-
_typ_map
= {'complex': <class 'complex'>, 'float': <class 'float'>, 'int': <class 'int'>, 'string': <class 'str'>}¶
-
-
class
OptionGroup
(name: str, description: str = '', parser: Optional[_pytest.config.argparsing.Parser] = None)[source]¶ Bases:
object
-
addoption
(*optnames: str, **attrs: Any) → None[source]¶ add an option to this group.
if a shortened version of a long option is specified it will be suppressed in the help. addoption(‘–twowords’, ‘–two-words’) results in help showing ‘–two-words’ only, but –twowords gets accepted and the automatic destination is in args.twowords
-
_addoption_instance
(option: _pytest.config.argparsing.Argument, shortupper: bool = False) → None[source]¶
-
-
class
StoreTrueWithNoPrefixAction
(option_strings, dest, default=False, required=False, help=None)[source]¶ Bases:
argparse._StoreTrueAction
Handle
--no-foo
for--foo
options.
-
class
MyOptionParser
(parser: _pytest.config.argparsing.Parser, extra_info: Optional[Dict[str, Any]] = None, prog: Optional[str] = None)[source]¶ Bases:
argparse.ArgumentParser
-
parse_args
(args: Optional[Sequence[str]] = None, namespace: Optional[argparse.Namespace] = None) → argparse.Namespace[source]¶ allow splitting of positional arguments
-
-
class
DropShorterLongHelpFormatter
(*args: Any, **kwargs: Any)[source]¶ Bases:
argparse.HelpFormatter
shorten help for long options that differ only in extra hyphens
collapse long options that are the same except for extra hyphens
shortcut if there are only two options and one of them is a short one
cache result on action object as this is called at least 2 times
-
_format_action_invocation
(action: argparse.Action) → str[source]¶