(config: Config)
| 156 | |
| 157 | |
| 158 | def showhelp(config: Config) -> None: |
| 159 | import textwrap |
| 160 | |
| 161 | reporter = config.pluginmanager.get_plugin("terminalreporter") |
| 162 | tw = reporter._tw |
| 163 | tw.write(config._parser.optparser.format_help()) |
| 164 | tw.line() |
| 165 | tw.line( |
| 166 | "[pytest] ini-options in the first pytest.ini|tox.ini|setup.cfg file found:" |
| 167 | ) |
| 168 | tw.line() |
| 169 | |
| 170 | columns = tw.fullwidth # costly call |
| 171 | indent_len = 24 # based on argparse's max_help_position=24 |
| 172 | indent = " " * indent_len |
| 173 | for name in config._parser._ininames: |
| 174 | help, type, default = config._parser._inidict[name] |
| 175 | if type is None: |
| 176 | type = "string" |
| 177 | if help is None: |
| 178 | raise TypeError(f"help argument cannot be None for {name}") |
| 179 | spec = f"{name} ({type}):" |
| 180 | tw.write(" %s" % spec) |
| 181 | spec_len = len(spec) |
| 182 | if spec_len > (indent_len - 3): |
| 183 | # Display help starting at a new line. |
| 184 | tw.line() |
| 185 | helplines = textwrap.wrap( |
| 186 | help, |
| 187 | columns, |
| 188 | initial_indent=indent, |
| 189 | subsequent_indent=indent, |
| 190 | break_on_hyphens=False, |
| 191 | ) |
| 192 | |
| 193 | for line in helplines: |
| 194 | tw.line(line) |
| 195 | else: |
| 196 | # Display help starting after the spec, following lines indented. |
| 197 | tw.write(" " * (indent_len - spec_len - 2)) |
| 198 | wrapped = textwrap.wrap(help, columns - indent_len, break_on_hyphens=False) |
| 199 | |
| 200 | if wrapped: |
| 201 | tw.line(wrapped[0]) |
| 202 | for line in wrapped[1:]: |
| 203 | tw.line(indent + line) |
| 204 | |
| 205 | tw.line() |
| 206 | tw.line("environment variables:") |
| 207 | vars = [ |
| 208 | ("PYTEST_ADDOPTS", "extra command line options"), |
| 209 | ("PYTEST_PLUGINS", "comma-separated plugins to load during startup"), |
| 210 | ("PYTEST_DISABLE_PLUGIN_AUTOLOAD", "set to disable plugin auto-loading"), |
| 211 | ("PYTEST_DEBUG", "set to enable debug tracing of pytest's internals"), |
| 212 | ] |
| 213 | for name, help in vars: |
| 214 | tw.line(f" {name:<24} {help}") |
| 215 | tw.line() |
no test coverage detected