Skip to content

Commit 85b8c63

Browse files
TST/CLN: return pytest MarkDecorator from td.skip_if_no
1 parent 649ad5c commit 85b8c63

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

pandas/tests/io/test_html.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ def test_same_ordering(datapath):
7777

7878

7979
@pytest.mark.parametrize("flavor", [
80-
pytest.param('bs4', marks=pytest.mark.skipif(
81-
not td.safe_import('lxml'), reason='No bs4')),
82-
pytest.param('lxml', marks=pytest.mark.skipif(
83-
not td.safe_import('lxml'), reason='No lxml'))], scope="class")
80+
pytest.param('bs4', marks=td.skip_if_no('lxml')),
81+
pytest.param('lxml', marks=td.skip_if_no('lxml'))], scope="class")
8482
class TestReadHtml:
8583

8684
@pytest.fixture(autouse=True)

pandas/util/_test_decorators.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,36 +99,40 @@ def _skip_if_no_scipy():
9999

100100
def skip_if_no(package, min_version=None):
101101
"""
102-
Generic function to help skip test functions when required packages are not
102+
Generic function to help skip tests when required packages are not
103103
present on the testing system.
104104
105-
Intended for use as a decorator, this function will wrap the decorated
106-
function with a pytest ``skip_if`` mark. During a pytest test suite
107-
execution, that mark will attempt to import the specified ``package`` and
108-
optionally ensure it meets the ``min_version``. If the import and version
109-
check are unsuccessful, then the decorated function will be skipped.
105+
This function returns a pytest mark with a skip condition that will be
106+
evaluated during test collection. An attempt will be made to import the
107+
specified ``package`` and optionally ensure it meets the ``min_version``
108+
109+
The mark can be used as either a decorator for a test function or to be
110+
applied to parameters in pytest.mark.parametrize calls or parametrized
111+
fixtures.
112+
113+
If the import and version check are unsuccessful, then the test function
114+
(or test case when used in conjunction with parametrization) will be
115+
skipped.
110116
111117
Parameters
112118
----------
113119
package: str
114-
The name of the package required by the decorated function
120+
The name of the required package.
115121
min_version: str or None, default None
116-
Optional minimum version of the package required by the decorated
117-
function
122+
Optional minimum version of the package.
118123
119124
Returns
120125
-------
121-
decorated_func: function
122-
The decorated function wrapped within a pytest ``skip_if`` mark
126+
_pytest.mark.structures.MarkDecorator
127+
a pytest.mark.skipif to use as either a test decorator or a
128+
parametrization mark.
123129
"""
124-
def decorated_func(func):
125-
msg = "Could not import '{}'".format(package)
126-
if min_version:
127-
msg += " satisfying a min_version of {}".format(min_version)
128-
return pytest.mark.skipif(
129-
not safe_import(package, min_version=min_version), reason=msg
130-
)(func)
131-
return decorated_func
130+
msg = "Could not import '{}'".format(package)
131+
if min_version:
132+
msg += " satisfying a min_version of {}".format(min_version)
133+
return pytest.mark.skipif(
134+
not safe_import(package, min_version=min_version), reason=msg
135+
)
132136

133137

134138
skip_if_no_mpl = pytest.mark.skipif(_skip_if_no_mpl(),

0 commit comments

Comments
 (0)