Skip to content

Commit 85a714c

Browse files
[Data] Create unit test directory for fast, isolated tests (#58445)
## Summary Creates a dedicated `tests/unit/` directory for unit tests that don't require Ray runtime or external dependencies. ## Changes - Created `tests/unit/` directory structure - Moved 13 pure unit tests to `tests/unit/` - Added `conftest.py` with fixtures to prevent `ray.init()` and `time.sleep()` - Added `README.md` documenting unit test requirements - Updated `BUILD.bazel` to run unit tests with "small" size tag ## Test Files Moved 1. test_arrow_type_conversion.py 2. test_block.py 3. test_block_boundaries.py 4. test_data_batch_conversion.py 5. test_datatype.py 6. test_deduping_schema.py 7. test_expression_evaluator.py 8. test_expressions.py 9. test_filename_provider.py 10. test_logical_plan.py 11. test_object_extension.py 12. test_path_util.py 13. test_ruleset.py These tests are fast (<1s each), isolated (no Ray runtime), and deterministic (no time.sleep or randomness). --------- Signed-off-by: Balaji Veeramani <bveeramani@berkeley.edu> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 7eca669 commit 85a714c

17 files changed

+63
-177
lines changed

python/ray/data/BUILD.bazel

Lines changed: 13 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ py_library(
2727
deps = ["//python/ray/tests:conftest"],
2828
)
2929

30+
py_test_module_list(
31+
size = "small",
32+
files = glob(["tests/unit/**/test_*.py"]),
33+
tags = [
34+
"exclusive",
35+
"team:data",
36+
],
37+
deps = [
38+
":conftest",
39+
"//:ray_lib",
40+
],
41+
)
42+
3043
py_test_module_list(
3144
size = "medium",
3245
files = glob(["tests/block_batching/test_*.py"]),
@@ -124,16 +137,6 @@ py_test(
124137
],
125138
)
126139

127-
py_test(
128-
name = "test_datatype",
129-
size = "small",
130-
srcs = ["tests/test_datatype.py"],
131-
tags = [
132-
"exclusive",
133-
"team:data",
134-
],
135-
)
136-
137140
py_test(
138141
name = "test_sql",
139142
size = "small",
@@ -207,22 +210,6 @@ py_test(
207210
],
208211
)
209212

210-
py_test(
211-
name = "test_arrow_type_conversion",
212-
size = "small",
213-
srcs = [
214-
"tests/test_arrow_type_conversion.py",
215-
],
216-
tags = [
217-
"exclusive",
218-
"team:data",
219-
],
220-
deps = [
221-
":conftest",
222-
"//:ray_lib",
223-
],
224-
)
225-
226213
py_test(
227214
name = "test_arrow_serialization",
228215
size = "small",
@@ -295,20 +282,6 @@ py_test(
295282
],
296283
)
297284

298-
py_test(
299-
name = "test_block",
300-
size = "small",
301-
srcs = ["tests/test_block.py"],
302-
tags = [
303-
"exclusive",
304-
"team:data",
305-
],
306-
deps = [
307-
":conftest",
308-
"//:ray_lib",
309-
],
310-
)
311-
312285
py_test(
313286
name = "test_block_batching",
314287
size = "medium",
@@ -365,20 +338,6 @@ py_test(
365338
],
366339
)
367340

368-
py_test(
369-
name = "test_expressions",
370-
size = "small",
371-
srcs = ["tests/test_expressions.py"],
372-
tags = [
373-
"exclusive",
374-
"team:data",
375-
],
376-
deps = [
377-
":conftest",
378-
"//:ray_lib",
379-
],
380-
)
381-
382341
py_test(
383342
name = "test_avro",
384343
size = "small",
@@ -605,31 +564,6 @@ py_test(
605564
],
606565
)
607566

608-
py_test(
609-
name = "test_data_batch_conversion",
610-
size = "small",
611-
srcs = ["tests/test_data_batch_conversion.py"],
612-
tags = [
613-
"exclusive",
614-
"team:data",
615-
],
616-
deps = [
617-
":conftest",
618-
"//:ray_lib",
619-
],
620-
)
621-
622-
py_test(
623-
name = "test_deduping_schema",
624-
size = "small",
625-
srcs = ["tests/test_deduping_schema.py"],
626-
tags = [
627-
"exclusive",
628-
"team:data",
629-
],
630-
deps = [],
631-
)
632-
633567
py_test(
634568
name = "test_ecosystem_modin",
635569
size = "small",
@@ -688,20 +622,6 @@ py_test(
688622
],
689623
)
690624

691-
py_test(
692-
name = "test_filename_provider",
693-
size = "small",
694-
srcs = ["tests/test_filename_provider.py"],
695-
tags = [
696-
"exclusive",
697-
"team:data",
698-
],
699-
deps = [
700-
":conftest",
701-
"//:ray_lib",
702-
],
703-
)
704-
705625
py_test(
706626
name = "test_hash_shuffle",
707627
size = "small",
@@ -941,20 +861,6 @@ py_test(
941861
],
942862
)
943863

944-
py_test(
945-
name = "test_path_util",
946-
size = "small",
947-
srcs = ["tests/test_path_util.py"],
948-
tags = [
949-
"exclusive",
950-
"team:data",
951-
],
952-
deps = [
953-
":conftest",
954-
"//:ray_lib",
955-
],
956-
)
957-
958864
py_test(
959865
name = "test_task_pool_map_operator",
960866
size = "small",
@@ -1237,20 +1143,6 @@ py_test(
12371143
],
12381144
)
12391145

1240-
py_test(
1241-
name = "test_object_extension",
1242-
size = "small",
1243-
srcs = ["tests/test_object_extension.py"],
1244-
tags = [
1245-
"exclusive",
1246-
"team:data",
1247-
],
1248-
deps = [
1249-
":conftest",
1250-
"//:ray_lib",
1251-
],
1252-
)
1253-
12541146
py_test(
12551147
name = "test_object_gc",
12561148
size = "large",
@@ -1378,20 +1270,6 @@ py_test(
13781270
],
13791271
)
13801272

1381-
py_test(
1382-
name = "test_ruleset",
1383-
size = "small",
1384-
srcs = ["tests/test_ruleset.py"],
1385-
tags = [
1386-
"exclusive",
1387-
"team:data",
1388-
],
1389-
deps = [
1390-
":conftest",
1391-
"//:ray_lib",
1392-
],
1393-
)
1394-
13951273
py_test(
13961274
name = "test_size_estimation",
13971275
size = "medium",
@@ -1715,20 +1593,6 @@ py_test(
17151593
],
17161594
)
17171595

1718-
py_test(
1719-
name = "test_logical_plan",
1720-
size = "small",
1721-
srcs = ["tests/test_logical_plan.py"],
1722-
tags = [
1723-
"exclusive",
1724-
"team:data",
1725-
],
1726-
deps = [
1727-
":conftest",
1728-
"//:ray_lib",
1729-
],
1730-
)
1731-
17321596
py_test(
17331597
name = "test_mcap",
17341598
size = "medium",
@@ -1785,34 +1649,6 @@ py_test(
17851649
],
17861650
)
17871651

1788-
py_test(
1789-
name = "test_expression_evaluator",
1790-
size = "small",
1791-
srcs = ["tests/test_expression_evaluator.py"],
1792-
tags = [
1793-
"exclusive",
1794-
"team:data",
1795-
],
1796-
deps = [
1797-
":conftest",
1798-
"//:ray_lib",
1799-
],
1800-
)
1801-
1802-
py_test(
1803-
name = "test_block_boundaries",
1804-
size = "small",
1805-
srcs = ["tests/test_block_boundaries.py"],
1806-
tags = [
1807-
"exclusive",
1808-
"team:data",
1809-
],
1810-
deps = [
1811-
":conftest",
1812-
"//:ray_lib",
1813-
],
1814-
)
1815-
18161652
py_test(
18171653
name = "test_telemetry",
18181654
size = "medium",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Unit Tests
2+
3+
This directory contains unit tests that do not depend on distributed infrastructure or external dependencies.
4+
5+
## Requirements
6+
7+
Unit tests in this directory must be:
8+
- **Fast**: Execute in milliseconds, not seconds
9+
- **Isolated**: No dependencies on Ray runtime, external services, or file I/O
10+
- **Deterministic**: No randomness or time-based behavior
11+
12+
## Restrictions
13+
14+
Tests should NOT:
15+
- Initialize or use the Ray distributed runtime
16+
- Use `time.sleep()` or other time-based delays
17+
- Depend on external services, databases, or file systems
18+
- Make network calls
19+
20+
## Enforcement
21+
22+
The `conftest.py` in this directory enforces these restrictions by preventing:
23+
- `ray.init()` from being called
24+
- `time.sleep()` from being used
25+
26+
If a test requires any of these, it should be moved to the main test directory instead.

python/ray/data/tests/unit/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import time
2+
3+
import pytest
4+
5+
import ray
6+
7+
8+
@pytest.fixture(autouse=True)
9+
def disallow_ray_init(monkeypatch):
10+
def raise_on_init(*args, **kwargs):
11+
raise RuntimeError("Unit tests should not depend on Ray being initialized.")
12+
13+
monkeypatch.setattr(ray, "init", raise_on_init)
14+
15+
16+
@pytest.fixture(autouse=True)
17+
def disallow_time_sleep(monkeypatch):
18+
def raise_on_sleep(seconds):
19+
raise RuntimeError(
20+
f"Unit tests should not use time.sleep({seconds}). "
21+
"Unit tests should be fast and deterministic."
22+
)
23+
24+
monkeypatch.setattr(time, "sleep", raise_on_sleep)
File renamed without changes.

0 commit comments

Comments
 (0)