(config: Config)
| 178 | |
| 179 | |
| 180 | def showhelp(config: Config) -> None: |
| 181 | import textwrap |
| 182 | |
| 183 | reporter: TerminalReporter | None = config.pluginmanager.get_plugin( |
| 184 | "terminalreporter" |
| 185 | ) |
| 186 | assert reporter is not None |
| 187 | tw = reporter._tw |
| 188 | tw.write(config._parser.optparser.format_help()) |
| 189 | tw.line() |
| 190 | tw.line( |
| 191 | "[pytest] configuration options in the first " |
| 192 | "pytest.toml|pytest.ini|tox.ini|setup.cfg|pyproject.toml file found:" |
| 193 | ) |
| 194 | tw.line() |
| 195 | |
| 196 | columns = tw.fullwidth # costly call |
| 197 | indent_len = 24 # based on argparse's max_help_position=24 |
| 198 | indent = " " * indent_len |
| 199 | for name in config._parser._inidict: |
| 200 | help, type, _default = config._parser._inidict[name] |
| 201 | if help is None: |
| 202 | raise TypeError(f"help argument cannot be None for {name}") |
| 203 | spec = f"{name} ({type}):" |
| 204 | tw.write(f" {spec}") |
| 205 | spec_len = len(spec) |
| 206 | if spec_len > (indent_len - 3): |
| 207 | # Display help starting at a new line. |
| 208 | tw.line() |
| 209 | helplines = textwrap.wrap( |
| 210 | help, |
| 211 | columns, |
| 212 | initial_indent=indent, |
| 213 | subsequent_indent=indent, |
| 214 | break_on_hyphens=False, |
| 215 | ) |
| 216 | |
| 217 | for line in helplines: |
| 218 | tw.line(line) |
| 219 | else: |
| 220 | # Display help starting after the spec, following lines indented. |
| 221 | tw.write(" " * (indent_len - spec_len - 2)) |
| 222 | wrapped = textwrap.wrap(help, columns - indent_len, break_on_hyphens=False) |
| 223 | |
| 224 | if wrapped: |
| 225 | tw.line(wrapped[0]) |
| 226 | for line in wrapped[1:]: |
| 227 | tw.line(indent + line) |
| 228 | |
| 229 | tw.line() |
| 230 | tw.line("Environment variables:") |
| 231 | vars = [ |
| 232 | ( |
| 233 | "CI", |
| 234 | "When set to a non-empty value, pytest knows it is running in a " |
| 235 | "CI process and does not truncate summary info", |
| 236 | ), |
| 237 | ("BUILD_NUMBER", "Equivalent to CI"), |
no test coverage detected