diff options
author | Ran Benita <ran@unusedvar.com> | 2020-12-20 15:36:24 +0200 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2020-12-20 15:59:20 +0200 |
commit | 6aa4d1c7ab968aecf44ad89e568a4515bd7e5343 (patch) | |
tree | 267cac94cd4d8200751ac7e4987393da0c1d3b2a /src | |
parent | 69c302479e3f76450f29e7d2de24254d5eda6492 (diff) | |
download | pytest-6aa4d1c7ab968aecf44ad89e568a4515bd7e5343.tar.gz |
mark: export pytest.MarkGenerator for typing purposes
The type cannot be constructed directly, but is exported for use in type
annotations, since it is reachable through existing public API.
Diffstat (limited to 'src')
-rw-r--r-- | src/_pytest/mark/structures.py | 11 | ||||
-rw-r--r-- | src/pytest/__init__.py | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 8bce33e68..ae6920735 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -488,9 +488,6 @@ class MarkGenerator: applies a 'slowtest' :class:`Mark` on ``test_function``. """ - _config: Optional[Config] = None - _markers: Set[str] = set() - # See TYPE_CHECKING above. if TYPE_CHECKING: skip: _SkipMarkDecorator @@ -500,7 +497,13 @@ class MarkGenerator: usefixtures: _UsefixturesMarkDecorator filterwarnings: _FilterwarningsMarkDecorator + def __init__(self, *, _ispytest: bool = False) -> None: + check_ispytest(_ispytest) + self._config: Optional[Config] = None + self._markers: Set[str] = set() + def __getattr__(self, name: str) -> MarkDecorator: + """Generate a new :class:`MarkDecorator` with the given name.""" if name[0] == "_": raise AttributeError("Marker name must NOT start with underscore") @@ -541,7 +544,7 @@ class MarkGenerator: return MarkDecorator(Mark(name, (), {}, _ispytest=True), _ispytest=True) -MARK_GEN = MarkGenerator() +MARK_GEN = MarkGenerator(_ispytest=True) @final diff --git a/src/pytest/__init__.py b/src/pytest/__init__.py index 1d5b38ee0..74cf00ee2 100644 --- a/src/pytest/__init__.py +++ b/src/pytest/__init__.py @@ -24,6 +24,7 @@ from _pytest.main import Session from _pytest.mark import Mark from _pytest.mark import MARK_GEN as mark from _pytest.mark import MarkDecorator +from _pytest.mark import MarkGenerator from _pytest.mark import param from _pytest.monkeypatch import MonkeyPatch from _pytest.nodes import Collector @@ -93,6 +94,7 @@ __all__ = [ "mark", "Mark", "MarkDecorator", + "MarkGenerator", "Module", "MonkeyPatch", "Package", |