Skip to content

Commit 37ae5c4

Browse files
authored
TST: Simplify and clarify test skipping (#56027)
* TST: Simplify and clarify test skipping * Typo * Update pandas/tests/arithmetic/test_datetime64.py * Don't skip because of duplicates
1 parent fd55cbe commit 37ae5c4

28 files changed

+94
-180
lines changed

pandas/tests/arithmetic/test_datetime64.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def test_dti_cmp_datetimelike(self, other, tz_naive_fixture):
414414
dti = date_range("2016-01-01", periods=2, tz=tz)
415415
if tz is not None:
416416
if isinstance(other, np.datetime64):
417-
pytest.skip("no tzaware version available")
417+
pytest.skip(f"{type(other).__name__} is not tz aware")
418418
other = localize_pydatetime(other, dti.tzinfo)
419419

420420
result = dti == other

pandas/tests/arithmetic/test_numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def test_divmod_zero(self, zero, numeric_idx):
384384
def test_div_negative_zero(self, zero, numeric_idx, op):
385385
# Check that -1 / -0.0 returns np.inf, not -np.inf
386386
if numeric_idx.dtype == np.uint64:
387-
pytest.skip(f"Not relevant for {numeric_idx.dtype}")
387+
pytest.skip(f"Div by negative 0 not relevant for {numeric_idx.dtype}")
388388
idx = numeric_idx - 3
389389

390390
expected = Index([-np.inf, -np.inf, -np.inf, np.nan, np.inf], dtype=np.float64)

pandas/tests/computation/test_eval.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
reason=f"numexpr enabled->{USE_NUMEXPR}, "
6464
f"installed->{NUMEXPR_INSTALLED}",
6565
),
66-
td.skip_if_no_ne,
66+
td.skip_if_no("numexpr"),
6767
],
6868
)
6969
for engine in ENGINES
@@ -1687,14 +1687,14 @@ def test_empty_globals(self, engine, parser):
16871687
pd.eval(e, engine=engine, parser=parser, global_dict={})
16881688

16891689

1690-
@td.skip_if_no_ne
1690+
@td.skip_if_no("numexpr")
16911691
def test_invalid_engine():
16921692
msg = "Invalid engine 'asdf' passed"
16931693
with pytest.raises(KeyError, match=msg):
16941694
pd.eval("x + y", local_dict={"x": 1, "y": 2}, engine="asdf")
16951695

16961696

1697-
@td.skip_if_no_ne
1697+
@td.skip_if_no("numexpr")
16981698
@pytest.mark.parametrize(
16991699
("use_numexpr", "expected"),
17001700
(
@@ -1711,7 +1711,7 @@ def test_numexpr_option_respected(use_numexpr, expected):
17111711
assert result == expected
17121712

17131713

1714-
@td.skip_if_no_ne
1714+
@td.skip_if_no("numexpr")
17151715
def test_numexpr_option_incompatible_op():
17161716
# GH 32556
17171717
with pd.option_context("compute.use_numexpr", False):
@@ -1723,7 +1723,7 @@ def test_numexpr_option_incompatible_op():
17231723
tm.assert_frame_equal(result, expected)
17241724

17251725

1726-
@td.skip_if_no_ne
1726+
@td.skip_if_no("numexpr")
17271727
def test_invalid_parser():
17281728
msg = "Invalid parser 'asdf' passed"
17291729
with pytest.raises(KeyError, match=msg):

pandas/tests/dtypes/test_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_is_object():
196196

197197

198198
@pytest.mark.parametrize(
199-
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
199+
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no("scipy"))]
200200
)
201201
def test_is_sparse(check_scipy):
202202
msg = "is_sparse is deprecated"
@@ -632,7 +632,7 @@ def test_is_bool_dtype_numpy_error():
632632

633633

634634
@pytest.mark.parametrize(
635-
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
635+
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no("scipy"))]
636636
)
637637
def test_is_extension_array_dtype(check_scipy):
638638
assert not com.is_extension_array_dtype([1, 2, 3])

pandas/tests/extension/base/dim2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def skip_if_doesnt_support_2d(self, dtype, request):
2929
test_func = node._obj
3030
if test_func.__qualname__.startswith("Dim2CompatTests"):
3131
# TODO: is there a less hacky way of checking this?
32-
pytest.skip("Test is only for EAs that support 2D.")
32+
pytest.skip(f"{dtype} does not support 2D.")
3333

3434
def test_transpose(self, data):
3535
arr2d = data.repeat(2).reshape(-1, 2)

pandas/tests/extension/base/interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_copy(self, data):
103103
result = data.copy()
104104

105105
if data.dtype._is_immutable:
106-
pytest.skip("test_copy assumes mutability")
106+
pytest.skip(f"test_copy assumes mutability and {data.dtype} is immutable")
107107

108108
data[1] = data[0]
109109
assert result[1] != result[0]
@@ -118,7 +118,7 @@ def test_view(self, data):
118118
assert type(result) == type(data)
119119

120120
if data.dtype._is_immutable:
121-
pytest.skip("test_view assumes mutability")
121+
pytest.skip(f"test_view assumes mutability and {data.dtype} is immutable")
122122

123123
result[1] = result[0]
124124
assert data[1] == data[0]

pandas/tests/extension/base/reduce.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_reduce_frame(self, data, all_numeric_reductions, skipna):
120120
op_name = all_numeric_reductions
121121
ser = pd.Series(data)
122122
if not is_numeric_dtype(ser.dtype):
123-
pytest.skip("not numeric dtype")
123+
pytest.skip(f"{ser.dtype} is not numeric dtype")
124124

125125
if op_name in ["count", "kurt", "sem"]:
126126
pytest.skip(f"{op_name} not an array method")

pandas/tests/extension/base/reshaping.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def test_ravel(self, data):
343343
assert type(result) == type(data)
344344

345345
if data.dtype._is_immutable:
346-
pytest.skip("test_ravel assumes mutability")
346+
pytest.skip(f"test_ravel assumes mutability and {data.dtype} is immutable")
347347

348348
# Check that we have a view, not a copy
349349
result[0] = result[1]
@@ -360,7 +360,9 @@ def test_transpose(self, data):
360360
assert result.shape == data.shape[::-1]
361361

362362
if data.dtype._is_immutable:
363-
pytest.skip("test_transpose assumes mutability")
363+
pytest.skip(
364+
f"test_transpose assumes mutability and {data.dtype} is immutable"
365+
)
364366

365367
# Check that we have a view, not a copy
366368
result[0] = result[1]

pandas/tests/extension/base/setitem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def skip_if_immutable(self, dtype, request):
4343
# This fixture is auto-used, but we want to not-skip
4444
# test_is_immutable.
4545
return
46-
pytest.skip("__setitem__ test not applicable with immutable dtype")
46+
pytest.skip(f"__setitem__ test not applicable with immutable dtype {dtype}")
4747

4848
def test_is_immutable(self, data):
4949
if data.dtype._is_immutable:

pandas/tests/extension/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def data_for_twos(dtype):
3737
if not (dtype._is_numeric or dtype.kind == "m"):
3838
# Object-dtypes may want to allow this, but for the most part
3939
# only numeric and timedelta-like dtypes will need to implement this.
40-
pytest.skip("Not a numeric dtype")
40+
pytest.skip(f"{dtype} is not a numeric dtype")
4141

4242
raise NotImplementedError
4343

0 commit comments

Comments
 (0)