Skip to content

Commit

Permalink
TYP: annotate testing decorators with pytest.MarkDecorator (pandas-de…
Browse files Browse the repository at this point in the history
…v#53794)

TYP: type pytest.MarkDecorator
  • Loading branch information
fangchenli authored and root committed Jun 23, 2023
1 parent 40aa4b6 commit 70f0558
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pandas/util/_test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,27 @@ def _skip_if_no_scipy() -> bool:
)


# TODO(pytest#7469): return type, _pytest.mark.structures.MarkDecorator is not public
# https://github.com/pytest-dev/pytest/issues/7469
def skip_if_installed(package: str):
def skip_if_installed(package: str) -> pytest.MarkDecorator:
"""
Skip a test if a package is installed.
Parameters
----------
package : str
The name of the package.
Returns
-------
pytest.MarkDecorator
a pytest.mark.skipif to use as either a test decorator or a
parametrization mark.
"""
return pytest.mark.skipif(
safe_import(package), reason=f"Skipping because {package} is installed."
)


# TODO(pytest#7469): return type, _pytest.mark.structures.MarkDecorator is not public
# https://github.com/pytest-dev/pytest/issues/7469
def skip_if_no(package: str, min_version: str | None = None):
def skip_if_no(package: str, min_version: str | None = None) -> pytest.MarkDecorator:
"""
Generic function to help skip tests when required packages are not
present on the testing system.
Expand All @@ -158,7 +160,7 @@ def skip_if_no(package: str, min_version: str | None = None):
Returns
-------
_pytest.mark.structures.MarkDecorator
pytest.MarkDecorator
a pytest.mark.skipif to use as either a test decorator or a
parametrization mark.
"""
Expand Down Expand Up @@ -189,9 +191,9 @@ def skip_if_no(package: str, min_version: str | None = None):
)


# TODO(pytest#7469): return type, _pytest.mark.structures.MarkDecorator is not public
# https://github.com/pytest-dev/pytest/issues/7469
def skip_if_np_lt(ver_str: str, *args, reason: str | None = None):
def skip_if_np_lt(
ver_str: str, *args, reason: str | None = None
) -> pytest.MarkDecorator:
if reason is None:
reason = f"NumPy {ver_str} or greater required"
return pytest.mark.skipif(
Expand Down

0 comments on commit 70f0558

Please sign in to comment.