Add command-line options for cache functionality. :param parser: Parser object to add command-line options to.
(parser: Parser)
| 470 | |
| 471 | |
| 472 | def pytest_addoption(parser: Parser) -> None: |
| 473 | """Add command-line options for cache functionality. |
| 474 | |
| 475 | :param parser: Parser object to add command-line options to. |
| 476 | """ |
| 477 | group = parser.getgroup("general") |
| 478 | group.addoption( |
| 479 | "--lf", |
| 480 | "--last-failed", |
| 481 | action="store_true", |
| 482 | dest="lf", |
| 483 | help="Rerun only the tests that failed at the last run (or all if none failed)", |
| 484 | ) |
| 485 | group.addoption( |
| 486 | "--ff", |
| 487 | "--failed-first", |
| 488 | action="store_true", |
| 489 | dest="failedfirst", |
| 490 | help="Run all tests, but run the last failures first. " |
| 491 | "This may re-order tests and thus lead to " |
| 492 | "repeated fixture setup/teardown.", |
| 493 | ) |
| 494 | group.addoption( |
| 495 | "--nf", |
| 496 | "--new-first", |
| 497 | action="store_true", |
| 498 | dest="newfirst", |
| 499 | help="Run tests from new files first, then the rest of the tests " |
| 500 | "sorted by file mtime", |
| 501 | ) |
| 502 | group.addoption( |
| 503 | "--cache-show", |
| 504 | action="append", |
| 505 | nargs="?", |
| 506 | dest="cacheshow", |
| 507 | help=( |
| 508 | "Show cache contents, don't perform collection or tests. " |
| 509 | "Optional argument: glob (default: '*')." |
| 510 | ), |
| 511 | ) |
| 512 | group.addoption( |
| 513 | "--cache-clear", |
| 514 | action="store_true", |
| 515 | dest="cacheclear", |
| 516 | help="Remove all cache contents at start of test run", |
| 517 | ) |
| 518 | cache_dir_default = ".pytest_cache" |
| 519 | if "TOX_ENV_DIR" in os.environ: |
| 520 | cache_dir_default = os.path.join(os.environ["TOX_ENV_DIR"], cache_dir_default) |
| 521 | parser.addini("cache_dir", default=cache_dir_default, help="Cache directory path") |
| 522 | group.addoption( |
| 523 | "--lfnf", |
| 524 | "--last-failed-no-failures", |
| 525 | action="store", |
| 526 | dest="last_failed_no_failures", |
| 527 | choices=("all", "none"), |
| 528 | default="all", |
| 529 | help="With ``--lf``, determines whether to execute tests when there " |