Repository: psf/black
File: tests/optional.py (Python)

Code before:
Mark tests to run only if an optional test ISN'T selected by prepending the mark with
"no_".

You can specify a "no_" prefix straight in config, in which case you can mark tests
to run when this tests ISN'T selected by omitting the "no_" prefix.

Specifying the name of the default behavior in `--run-optional=` is harmless.

Adapted from https://pypi.org/project/pytest-optional-tests/, (c) 2019 Reece Hart
"""

import itertools
import logging
import re
from functools import lru_cache
from typing import TYPE_CHECKING, FrozenSet, List, Set

import pytest

try:
    from pytest import StashKey
except ImportError:
    # pytest < 7
    #
    # "isort: skip" is needed or it moves the "type: ignore" to the following line
    # becuase of the line length, and then mypy complains.
    # Of course, adding the "isort: skip" means that
    # flake8-bugbear then also complains about the line length,
    # so we *also* need a "noqa" comment for good measure :)
    from _pytest.store import (  # type: ignore[import-not-found, no-redef]  # isort: skip  # noqa: B950
        StoreKey as StashKey,
    )

log = logging.getLogger(__name__)


if TYPE_CHECKING:
    from _pytest.config import Config
    from _pytest.config.argparsing import Parser
    from _pytest.mark.structures import MarkDecorator
    from _pytest.nodes import Node


ALL_POSSIBLE_OPTIONAL_MARKERS = StashKey[FrozenSet[str]]()
ENABLED_OPTIONAL_MARKERS = StashKey[FrozenSet[str]]()


def pytest_addoption(parser: "Parser") -> None:
    group = parser.getgroup("collect")
    group.addoption(
        "--run-optional",

Review comment (suggestion):
```suggestion
    # because of the line length, and then mypy complains.
```

Code after:
Mark tests to run only if an optional test ISN'T selected by prepending the mark with
"no_".

You can specify a "no_" prefix straight in config, in which case you can mark tests
to run when this tests ISN'T selected by omitting the "no_" prefix.

Specifying the name of the default behavior in `--run-optional=` is harmless.

Adapted from https://pypi.org/project/pytest-optional-tests/, (c) 2019 Reece Hart
"""

import itertools
import logging
import re
from functools import lru_cache
from typing import TYPE_CHECKING, FrozenSet, List, Set

import pytest

try:
    from pytest import StashKey
except ImportError:
    # pytest < 7
    #
    # "isort: skip" is needed or it moves the "type: ignore" to the following line
    # because of the line length, and then mypy complains.
    # Of course, adding the "isort: skip" means that
    # flake8-bugbear then also complains about the line length,
    # so we *also* need a "noqa" comment for good measure :)
    from _pytest.store import (  # type: ignore[import-not-found, no-redef]  # isort: skip  # noqa: B950
        StoreKey as StashKey,
    )

log = logging.getLogger(__name__)


if TYPE_CHECKING:
    from _pytest.config import Config
    from _pytest.config.argparsing import Parser
    from _pytest.mark.structures import MarkDecorator
    from _pytest.nodes import Node


ALL_POSSIBLE_OPTIONAL_MARKERS = StashKey[FrozenSet[str]]()
ENABLED_OPTIONAL_MARKERS = StashKey[FrozenSet[str]]()


def pytest_addoption(parser: "Parser") -> None:
    group = parser.getgroup("collect")
    group.addoption(
        "--run-optional",