def __init__( self, expected_warning: Optional[ Union[Type[Warning], Tuple[Type[Warning], ...]] ] = None, match_expr: Optional[Union[str, Pattern[str]]] = None, *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) super().__init__(_ispytest=True) msg = "exceptions must be derived from Warning, not %s" if expected_warning is None: expected_warning_tup = None elif isinstance(expected_warning, tuple): for exc in expected_warning: if not issubclass(exc, Warning): raise TypeError(msg % type(exc)) expected_warning_tup = expected_warning elif issubclass(expected_warning, Warning): expected_warning_tup = (expected_warning,) else: raise TypeError(msg % type(expected_warning)) self.expected_warning = expected_warning_tup self.match_expr = match_expr
def cache_dir_from_config(config: Config, *, _ispytest: bool = False) -> Path: """Get the path to the cache directory for a Config. :meta private: """ check_ispytest(_ispytest) return resolve_from_str(config.getini("cache_dir"), config.rootpath)
def __init__(self, cachedir: Path, config: Config, *, _ispytest: bool = False) -> None: check_ispytest(_ispytest) self._cachedir = cachedir self._config = config
def __init__( self, captureclass, request: SubRequest, *, _ispytest: bool = False ) -> None: check_ispytest(_ispytest) self.captureclass = captureclass self.request = request self._capture: Optional[MultiCapture[AnyStr]] = None self._captured_out = self.captureclass.EMPTY_BUFFER self._captured_err = self.captureclass.EMPTY_BUFFER
def for_config(cls, config: Config, *, _ispytest: bool = False) -> "Cache": """Create the Cache instance for a Config. :meta private: """ check_ispytest(_ispytest) cachedir = cls.cache_dir_from_config(config, _ispytest=True) if config.getoption("cacheclear") and cachedir.is_dir(): cls.clear_cache(cachedir, _ispytest=True) return cls(cachedir, config, _ispytest=True)
def clear_cache(cls, cachedir: Path, _ispytest: bool = False) -> None: """Clear the sub-directories used to hold cached directories and values. :meta private: """ check_ispytest(_ispytest) for prefix in (cls._CACHE_PREFIX_DIRS, cls._CACHE_PREFIX_VALUES): d = cachedir / prefix if d.is_dir(): rm_rf(d)
def __init__( self, excinfo: Optional[Tuple[Type["E"], "E", TracebackType]], striptext: str = "", traceback: Optional[Traceback] = None, *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) self._excinfo = excinfo self._striptext = striptext self._traceback = traceback
def __init__( self, name: str, description: str = "", parser: Optional[Parser] = None, *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) self.name = name self.description = description self.options: List[Argument] = [] self.parser = parser
def from_config( cls, config: Config, *, _ispytest: bool = False, ) -> "TempPathFactory": """Create a factory according to pytest configuration. :meta private: """ check_ispytest(_ispytest) return cls( given_basetemp=config.option.basetemp, trace=config.trace.get("tmpdir"), _ispytest=True, )
def warn(self, fmt: str, *, _ispytest: bool = False, **args: object) -> None: """Issue a cache warning. :meta private: """ check_ispytest(_ispytest) import warnings from _pytest.warning_types import PytestCacheWarning warnings.warn( PytestCacheWarning(fmt.format(**args) if args else fmt), self._config.hook, stacklevel=3, )
def __init__( self, usage: Optional[str] = None, processopt: Optional[Callable[["Argument"], None]] = None, *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) self._anonymous = OptionGroup("custom options", parser=self, _ispytest=True) self._groups: List[OptionGroup] = [] self._processopt = processopt self._usage = usage self._inidict: Dict[str, Tuple[str, Optional[str], Any]] = {} self._ininames: List[str] = [] self.extra_info: Dict[str, Any] = {}
def __init__( self, name: str, args: Tuple[Any, ...], kwargs: Mapping[str, Any], param_ids_from: Optional["Mark"] = None, param_ids_generated: Optional[Sequence[str]] = None, *, _ispytest: bool = False, ) -> None: """:meta private:""" check_ispytest(_ispytest) # Weirdness to bypass frozen=True. object.__setattr__(self, "name", name) object.__setattr__(self, "args", args) object.__setattr__(self, "kwargs", kwargs) object.__setattr__(self, "_param_ids_from", param_ids_from) object.__setattr__(self, "_param_ids_generated", param_ids_generated)
def __init__( self, given_basetemp: Optional[Path], trace, basetemp: Optional[Path] = None, *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) if given_basetemp is None: self._given_basetemp = None else: # Use os.path.abspath() to get absolute path instead of resolve() as it # does not work the same in all platforms (see #4427). # Path.absolute() exists, but it is not public (see https://bugs.python.org/issue25012). self._given_basetemp = Path(os.path.abspath(str(given_basetemp))) self._trace = trace self._basetemp = basetemp
def __init__( self, result: Optional[TResult], excinfo: Optional[ExceptionInfo[BaseException]], start: float, stop: float, duration: float, when: "Literal['collect', 'setup', 'call', 'teardown']", *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) self._result = result self.excinfo = excinfo self.start = start self.stop = stop self.duration = duration self.when = when
def __init__( self, tmppath_factory: TempPathFactory, *, _ispytest: bool = False ) -> None: check_ispytest(_ispytest) self._tmppath_factory = tmppath_factory
def __init__(self, *, _ispytest: bool = False) -> None: check_ispytest(_ispytest) self._config: Optional[Config] = None self._markers: Set[str] = set()
def __init__(self, item: nodes.Node, *, _ispytest: bool = False) -> None: check_ispytest(_ispytest) self._item = item self._initial_handler_level: Optional[int] = None # Dict of log name -> log level. self._initial_logger_levels: Dict[Optional[str], int] = {}
def __init__(self, *, _ispytest: bool = False) -> None: check_ispytest(_ispytest) # Type ignored due to the way typeshed handles warnings.catch_warnings. super().__init__(record=True) # type: ignore[call-arg] self._entered = False self._list: List[warnings.WarningMessage] = []
def __init__(self, foo: int, *, _ispytest: bool = False) -> None: deprecated.check_ispytest(_ispytest)
def __init__(self, mark: Mark, *, _ispytest: bool = False) -> None: """:meta private:""" check_ispytest(_ispytest) self.mark = mark