duty 1.3.0__py3-none-any.whl → 1.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
duty/tools/_pytest.py ADDED
@@ -0,0 +1,483 @@
1
+ """Callable for [pytest](https://github.com/pytest-dev/pytest)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Literal
6
+
7
+ from duty.tools._base import Tool
8
+
9
+
10
+ class pytest(Tool): # noqa: N801
11
+ """Call [pytest](https://github.com/pytest-dev/pytest)."""
12
+
13
+ cli_name = "pytest"
14
+
15
+ def __init__(
16
+ self,
17
+ *paths: str,
18
+ config_file: str | None = None,
19
+ select: str | None = None,
20
+ select_markers: str | None = None,
21
+ markers: bool | None = None,
22
+ exitfirst: bool | None = None,
23
+ fixtures: bool | None = None,
24
+ fixtures_per_test: bool | None = None,
25
+ pdb: bool | None = None,
26
+ pdbcls: str | None = None,
27
+ trace: bool | None = None,
28
+ capture: str | None = None,
29
+ runxfail: bool | None = None,
30
+ last_failed: bool | None = None,
31
+ failed_first: bool | None = None,
32
+ new_first: bool | None = None,
33
+ cache_show: str | None = None,
34
+ cache_clear: bool | None = None,
35
+ last_failed_no_failures: Literal["all", "none"] | None = None,
36
+ stepwise: bool | None = None,
37
+ stepwise_skip: bool | None = None,
38
+ durations: int | None = None,
39
+ durations_min: int | None = None,
40
+ verbose: bool | None = None,
41
+ no_header: bool | None = None,
42
+ no_summary: bool | None = None,
43
+ quiet: bool | None = None,
44
+ verbosity: int | None = None,
45
+ show_extra_summary: str | None = None,
46
+ disable_pytest_warnings: bool | None = None,
47
+ showlocals: bool | None = None,
48
+ no_showlocals: bool | None = None,
49
+ traceback: Literal["auto", "long", "short", "line", "native", "no"] | None = None,
50
+ show_capture: Literal["no", "stdout", "stderr", "log", "all"] | None = None,
51
+ full_trace: bool | None = None,
52
+ color: str | None = None,
53
+ code_highlight: bool | None = None,
54
+ pastebin: str | None = None,
55
+ junit_xml: str | None = None,
56
+ junit_prefix: str | None = None,
57
+ pythonwarnings: str | None = None,
58
+ maxfail: int | None = None,
59
+ strict_config: bool | None = None,
60
+ strict_markers: bool | None = None,
61
+ continue_on_collection_errors: bool | None = None,
62
+ rootdir: str | None = None,
63
+ collect_only: bool | None = None,
64
+ pyargs: bool | None = None,
65
+ ignore: list[str] | None = None,
66
+ ignore_glob: list[str] | None = None,
67
+ deselect: str | None = None,
68
+ confcutdir: str | None = None,
69
+ noconftest: bool | None = None,
70
+ keep_duplicates: bool | None = None,
71
+ collect_in_virtualenv: bool | None = None,
72
+ import_mode: Literal["prepend", "append", "importlib"] | None = None,
73
+ doctest_modules: bool | None = None,
74
+ doctest_report: Literal["none", "cdiff", "ndiff", "udiff", "only_first_failure"] | None = None,
75
+ doctest_glob: str | None = None,
76
+ doctest_ignore_import_errors: bool | None = None,
77
+ doctest_continue_on_failure: bool | None = None,
78
+ basetemp: str | None = None,
79
+ plugins: list[str] | None = None,
80
+ no_plugins: list[str] | None = None,
81
+ trace_config: bool | None = None,
82
+ debug: str | None = None,
83
+ override_ini: str | None = None,
84
+ assert_mode: str | None = None,
85
+ setup_only: bool | None = None,
86
+ setup_show: bool | None = None,
87
+ setup_plan: bool | None = None,
88
+ log_level: str | None = None,
89
+ log_format: str | None = None,
90
+ log_date_format: str | None = None,
91
+ log_cli_level: tuple[str, str] | None = None,
92
+ log_cli_format: str | None = None,
93
+ log_cli_date_format: str | None = None,
94
+ log_file: str | None = None,
95
+ log_file_level: str | None = None,
96
+ log_file_format: str | None = None,
97
+ log_file_date_format: str | None = None,
98
+ log_auto_indent: str | None = None,
99
+ ) -> None:
100
+ """Run `pytest`.
101
+
102
+ Parameters:
103
+ *paths: Files or directories to select tests from.
104
+ select: Only run tests which match the given substring expression. An expression is a Python evaluatable expression where all names are substring-matched against test names and their parent classes. Example: -k 'test_method or test_other' matches all test functions and classes whose name contains 'test_method' or 'test_other', while -k 'not test_method' matches those that don't contain 'test_method' in their names. -k 'not test_method and not test_other' will eliminate the matches. Additionally keywords are matched to classes and functions containing extra names in their 'extra_keyword_matches' set, as well as functions which have names assigned directly to them. The matching is case-insensitive.
105
+ select_markers: Only run tests matching given mark expression. For example: -m 'mark1 and not mark2'.
106
+ markers: show markers (builtin, plugin and per-project ones).
107
+ exitfirst: Exit instantly on first error or failed test
108
+ fixtures: Show available fixtures, sorted by plugin appearance (fixtures with leading '_' are only shown with '-v')
109
+ fixtures_per_test: Show fixtures per test
110
+ pdb: Start the interactive Python debugger on errors or KeyboardInterrupt
111
+ pdbcls: Specify a custom interactive Python debugger for use with --pdb.For example: --pdbcls IPython.terminal.debugger:TerminalPdb
112
+ trace: Immediately break when running each test
113
+ capture: Per-test capturing method: one of fd|sys|no|tee-sys
114
+ runxfail: Report the results of xfail tests as if they were not marked
115
+ last_failed: Rerun only the tests that failed at the last run (or all if none failed)
116
+ failed_first: Run all tests, but run the last failures first. This may re-order tests and thus lead to repeated fixture setup/teardown.
117
+ new_first: Run tests from new files first, then the rest of the tests sorted by file mtime
118
+ cache_show: Show cache contents, don't perform collection or tests. Optional argument: glob (default: '*').
119
+ cache_clear: Remove all cache contents at start of test run
120
+ last_failed_no_failures: Which tests to run with no previously (known) failures
121
+ stepwise: Exit on test failure and continue from last failing test next time
122
+ stepwise_skip: Ignore the first failing test but stop on the next failing test. Implicitly enables --stepwise.
123
+ durations: Show N slowest setup/test durations (N 0 for all)
124
+ durations_min: Minimal duration in seconds for inclusion in slowest list. Default: 0.005.
125
+ verbose: Increase verbosity
126
+ no_header: Disable header
127
+ no_summary: Disable summary
128
+ quiet: Decrease verbosity
129
+ verbosity: Set verbosity. Default: 0.
130
+ show_extra_summary: Show extra test summary info as specified by chars: (f)ailed, (E)rror, (s)kipped, (x)failed, (X)passed, (p)assed, (P)assed with output, (a)ll except passed (p/P), or (A)ll. (w)arnings are enabled by default (see --disable-warnings), 'N' can be used to reset the list. (default: 'fE').
131
+ disable_pytest_warnings: Disable warnings summary
132
+ showlocals: Show locals in tracebacks (disabled by default)
133
+ no_showlocals: Hide locals in tracebacks (negate --showlocals passed through addopts)
134
+ traceback: Traceback print mode (auto/long/short/line/native/no)
135
+ show_capture: Controls how captured stdout/stderr/log is shown on failed tests. Default: all.
136
+ full_trace: Don't cut any tracebacks (default is to cut)
137
+ color: Color terminal output (yes/no/auto)
138
+ code_highlight: {yes,no} Whether code should be highlighted (only if --color is also enabled). Default: yes.
139
+ pastebin: Send failed|all info to bpaste.net pastebin service
140
+ junit_xml: Create junit-xml style report file at given path
141
+ junit_prefix: Prepend prefix to classnames in junit-xml output
142
+ pythonwarnings: Set which warnings to report, see -W option of Python itself
143
+ maxfail: Exit after first num failures or errors
144
+ strict_config: Any warnings encountered while parsing the `pytest` section of the configuration file raise errors
145
+ strict_markers: Markers not registered in the `markers` section of the configuration file raise errors
146
+ config_file: Load configuration from `file` instead of trying to locate one of the implicit configuration files
147
+ continue_on_collection_errors: Force test execution even if collection errors occur
148
+ rootdir: Define root directory for tests. Can be relative path: 'root_dir', './root_dir', 'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: '$HOME/root_dir'.
149
+ collect_only: Only collect tests, don't execute them
150
+ pyargs: Try to interpret all arguments as Python packages
151
+ ignore: Ignore path during collection (multi-allowed)
152
+ ignore_glob: Ignore path pattern during collection (multi-allowed)
153
+ deselect: Deselect item (via node id prefix) during collection (multi-allowed)
154
+ confcutdir: Only load conftest.py's relative to specified dir
155
+ noconftest: Don't load any conftest.py files
156
+ keep_duplicates: Keep duplicate tests
157
+ collect_in_virtualenv: Don't ignore tests in a local virtualenv directory
158
+ import_mode: Prepend/append to sys.path when importing test modules and conftest files. Default: prepend.
159
+ doctest_modules: Run doctests in all .py modules
160
+ doctest_report: Choose another output format for diffs on doctest failure
161
+ doctest_glob: Doctests file matching pattern, default: test*.txt
162
+ doctest_ignore_import_errors: Ignore doctest ImportErrors
163
+ doctest_continue_on_failure: For a given doctest, continue to run after the first failure
164
+ basetemp: Base temporary directory for this test run. (Warning: this directory is removed if it exists.)
165
+ plugins: Early-load given plugin module name or entry point (multi-allowed). To avoid loading of plugins, use the `no:` prefix, e.g. `no:doctest`.
166
+ no_plugins: Early-load given plugin module name or entry point (multi-allowed). To avoid loading of plugins, use the `no:` prefix, e.g. `no:doctest`.
167
+ trace_config: Trace considerations of conftest.py files
168
+ debug: Store internal tracing debug information in this log file. This file is opened with 'w' and truncated as a result, care advised. Default: pytestdebug.log.
169
+ override_ini: Override ini option with "option value" style, e.g. `-o xfail_strict True -o cache_dir cache`.
170
+ assert_mode: Control assertion debugging tools. 'plain' performs no assertion debugging. 'rewrite' (the default) rewrites assert statements in test modules on import to provide assert expression information.
171
+ setup_only: Only setup fixtures, do not execute tests
172
+ setup_show: Show setup of fixtures while executing tests
173
+ setup_plan: Show what fixtures and tests would be executed but don't execute anything
174
+ log_level: Level of messages to catch/display. Not set by default, so it depends on the root/parent log handler's effective level, where it is "WARNING" by default.
175
+ log_format: Log format used by the logging module.
176
+ log_date_format: Log date format used by the logging module.
177
+ log_cli_level: logging level.
178
+ log_cli_format: Log format used by the logging module.
179
+ log_cli_date_format: Log date format used by the logging module.
180
+ log_file: Path to a file when logging will be written to.
181
+ log_file_level: Log file logging level.
182
+ log_file_format: Log format used by the logging module.
183
+ log_file_date_format: Log date format used by the logging module.
184
+ log_auto_indent: Auto-indent multiline messages passed to the logging module. Accepts true|on, false|off or an integer.
185
+ """
186
+ cli_args = list(paths)
187
+
188
+ if select:
189
+ cli_args.append("-k")
190
+ cli_args.append(select)
191
+
192
+ if select_markers:
193
+ cli_args.append("-m")
194
+ cli_args.append(select_markers)
195
+
196
+ if markers:
197
+ cli_args.append("--markers")
198
+
199
+ if exitfirst:
200
+ cli_args.append("--exitfirst")
201
+
202
+ if fixtures:
203
+ cli_args.append("--fixtures")
204
+
205
+ if fixtures_per_test:
206
+ cli_args.append("--fixtures-per-test")
207
+
208
+ if pdb:
209
+ cli_args.append("--pdb")
210
+
211
+ if pdbcls:
212
+ cli_args.append("--pdbcls")
213
+ cli_args.append(pdbcls)
214
+
215
+ if trace:
216
+ cli_args.append("--trace")
217
+
218
+ if capture:
219
+ cli_args.append("--capture")
220
+
221
+ if runxfail:
222
+ cli_args.append("--runxfail")
223
+
224
+ if last_failed:
225
+ cli_args.append("--last-failed")
226
+
227
+ if failed_first:
228
+ cli_args.append("--failed-first")
229
+
230
+ if new_first:
231
+ cli_args.append("--new-first")
232
+
233
+ if cache_show:
234
+ cli_args.append("--cache-show")
235
+ cli_args.append(cache_show)
236
+
237
+ if cache_clear:
238
+ cli_args.append("--cache-clear")
239
+
240
+ if last_failed_no_failures:
241
+ cli_args.append("--last-failed-no-failures")
242
+ cli_args.append(last_failed_no_failures)
243
+
244
+ if stepwise:
245
+ cli_args.append("--stepwise")
246
+
247
+ if stepwise_skip:
248
+ cli_args.append("--stepwise-skip")
249
+
250
+ if durations:
251
+ cli_args.append("--durations")
252
+ cli_args.append(str(durations))
253
+
254
+ if durations_min:
255
+ cli_args.append("--durations-min")
256
+ cli_args.append(str(durations_min))
257
+
258
+ if verbose:
259
+ cli_args.append("--verbose")
260
+
261
+ if no_header:
262
+ cli_args.append("--no-header")
263
+
264
+ if no_summary:
265
+ cli_args.append("--no-summary")
266
+
267
+ if quiet:
268
+ cli_args.append("--quiet")
269
+
270
+ if verbosity:
271
+ cli_args.append("--verbosity")
272
+ cli_args.append(str(verbosity))
273
+
274
+ if show_extra_summary:
275
+ cli_args.append("-r")
276
+ cli_args.append(show_extra_summary)
277
+
278
+ if disable_pytest_warnings:
279
+ cli_args.append("--disable-pytest-warnings")
280
+
281
+ if showlocals:
282
+ cli_args.append("--showlocals")
283
+
284
+ if no_showlocals:
285
+ cli_args.append("--no-showlocals")
286
+
287
+ if traceback:
288
+ cli_args.append("--tb")
289
+ cli_args.append(traceback)
290
+
291
+ if show_capture:
292
+ cli_args.append("--show-capture")
293
+ cli_args.append(show_capture)
294
+
295
+ if full_trace:
296
+ cli_args.append("--full-trace")
297
+
298
+ if color:
299
+ cli_args.append("--color")
300
+ cli_args.append(color)
301
+
302
+ if code_highlight:
303
+ cli_args.append("--code-highlight")
304
+
305
+ if pastebin:
306
+ cli_args.append("--pastebin")
307
+ cli_args.append(pastebin)
308
+
309
+ if junit_xml:
310
+ cli_args.append("--junit-xml")
311
+ cli_args.append(junit_xml)
312
+
313
+ if junit_prefix:
314
+ cli_args.append("--junit-prefix")
315
+ cli_args.append(junit_prefix)
316
+
317
+ if pythonwarnings:
318
+ cli_args.append("--pythonwarnings")
319
+ cli_args.append(pythonwarnings)
320
+
321
+ if maxfail:
322
+ cli_args.append("--maxfail")
323
+ cli_args.append(str(maxfail))
324
+
325
+ if strict_config:
326
+ cli_args.append("--strict-config")
327
+
328
+ if strict_markers:
329
+ cli_args.append("--strict-markers")
330
+
331
+ if config_file:
332
+ cli_args.append("-c")
333
+ cli_args.append(config_file)
334
+
335
+ if continue_on_collection_errors:
336
+ cli_args.append("--continue-on-collection-errors")
337
+
338
+ if rootdir:
339
+ cli_args.append("--rootdir")
340
+ cli_args.append(rootdir)
341
+
342
+ if collect_only:
343
+ cli_args.append("--collect-only")
344
+
345
+ if pyargs:
346
+ cli_args.append("--pyargs")
347
+
348
+ if ignore:
349
+ for ign in ignore:
350
+ cli_args.append("--ignore")
351
+ cli_args.append(ign)
352
+
353
+ if ignore_glob:
354
+ for ign_glob in ignore_glob:
355
+ cli_args.append("--ignore-glob")
356
+ cli_args.append(ign_glob)
357
+
358
+ if deselect:
359
+ cli_args.append("--deselect")
360
+ cli_args.append(deselect)
361
+
362
+ if confcutdir:
363
+ cli_args.append("--confcutdir")
364
+ cli_args.append(confcutdir)
365
+
366
+ if noconftest:
367
+ cli_args.append("--noconftest")
368
+
369
+ if keep_duplicates:
370
+ cli_args.append("--keep-duplicates")
371
+
372
+ if collect_in_virtualenv:
373
+ cli_args.append("--collect-in-virtualenv")
374
+
375
+ if import_mode:
376
+ cli_args.append("--import-mode")
377
+ cli_args.append(import_mode)
378
+
379
+ if doctest_modules:
380
+ cli_args.append("--doctest-modules")
381
+
382
+ if doctest_report:
383
+ cli_args.append("--doctest-report")
384
+ cli_args.append(doctest_report)
385
+
386
+ if doctest_glob:
387
+ cli_args.append("--doctest-glob")
388
+ cli_args.append(doctest_glob)
389
+
390
+ if doctest_ignore_import_errors:
391
+ cli_args.append("--doctest-ignore-import-errors")
392
+
393
+ if doctest_continue_on_failure:
394
+ cli_args.append("--doctest-continue-on-failure")
395
+
396
+ if basetemp:
397
+ cli_args.append("--basetemp")
398
+ cli_args.append(basetemp)
399
+
400
+ if plugins:
401
+ for plugin in plugins:
402
+ cli_args.append("-p")
403
+ cli_args.append(plugin)
404
+
405
+ if no_plugins:
406
+ for no_plugin in no_plugins:
407
+ cli_args.append("-p")
408
+ cli_args.append(f"no:{no_plugin}")
409
+
410
+ if trace_config:
411
+ cli_args.append("--trace-config")
412
+
413
+ if debug:
414
+ cli_args.append("--debug")
415
+ cli_args.append(debug)
416
+
417
+ if override_ini:
418
+ cli_args.append("--override-ini")
419
+ cli_args.append(override_ini)
420
+
421
+ if assert_mode:
422
+ cli_args.append("--assert")
423
+ cli_args.append(assert_mode)
424
+
425
+ if setup_only:
426
+ cli_args.append("--setup-only")
427
+
428
+ if setup_show:
429
+ cli_args.append("--setup-show")
430
+
431
+ if setup_plan:
432
+ cli_args.append("--setup-plan")
433
+
434
+ if log_level:
435
+ cli_args.append("--log-level")
436
+ cli_args.append(log_level)
437
+
438
+ if log_format:
439
+ cli_args.append("--log-format")
440
+ cli_args.append(log_format)
441
+
442
+ if log_date_format:
443
+ cli_args.append("--log-date-format")
444
+ cli_args.append(log_date_format)
445
+
446
+ if log_cli_level:
447
+ cli_args.append("--log-cli-level")
448
+ cli_args.extend(log_cli_level)
449
+
450
+ if log_cli_format:
451
+ cli_args.append("--log-cli-format")
452
+ cli_args.append(log_cli_format)
453
+
454
+ if log_cli_date_format:
455
+ cli_args.append("--log-cli-date-format")
456
+ cli_args.append(log_cli_date_format)
457
+
458
+ if log_file:
459
+ cli_args.append("--log-file")
460
+ cli_args.append(log_file)
461
+
462
+ if log_file_level:
463
+ cli_args.append("--log-file-level")
464
+ cli_args.append(log_file_level)
465
+
466
+ if log_file_format:
467
+ cli_args.append("--log-file-format")
468
+ cli_args.append(log_file_format)
469
+
470
+ if log_file_date_format:
471
+ cli_args.append("--log-file-date-format")
472
+ cli_args.append(log_file_date_format)
473
+
474
+ if log_auto_indent:
475
+ cli_args.append("--log-auto-indent")
476
+ cli_args.append(log_auto_indent)
477
+
478
+ super().__init__(cli_args)
479
+
480
+ def __call__(self) -> int:
481
+ from pytest import main as run_pytest # noqa: PT013
482
+
483
+ return run_pytest(self.cli_args)