|
1 | 1 | import os |
| 2 | +import sys |
2 | 3 | import warnings |
3 | 4 | from importlib import import_module |
4 | 5 | from pathlib import Path |
@@ -35,6 +36,46 @@ def import_pandas(): |
35 | 36 | pytest.skip("Couldn't import pandas") |
36 | 37 |
|
37 | 38 |
|
| 39 | +@pytest.hookimpl(hookwrapper=True) |
| 40 | +def pytest_runtest_call(item): |
| 41 | + """Convert missing pyarrow imports to skips. |
| 42 | +
|
| 43 | + TODO(evertlammerts): Remove skip when pyarrow releases for 3.14. |
| 44 | + https://github.com/duckdblabs/duckdb-internal/issues/6182 |
| 45 | + """ |
| 46 | + outcome = yield |
| 47 | + if sys.version_info[:2] == (3, 14): |
| 48 | + try: |
| 49 | + outcome.get_result() |
| 50 | + except ImportError as e: |
| 51 | + if e.name == "pyarrow": |
| 52 | + pytest.skip(f"pyarrow not available - {item.name} requires pyarrow") |
| 53 | + else: |
| 54 | + raise |
| 55 | + |
| 56 | + |
| 57 | +@pytest.hookimpl(hookwrapper=True) |
| 58 | +def pytest_make_collect_report(collector): |
| 59 | + """Wrap module collection to catch pyarrow import errors on Python 3.14. |
| 60 | +
|
| 61 | + If we're on Python 3.14 and a test module raises ModuleNotFoundError |
| 62 | + for 'pyarrow', mark the entire module as xfailed rather than failing collection. |
| 63 | +
|
| 64 | + TODO(evertlammerts): Remove skip when pyarrow releases for 3.14. |
| 65 | + https://github.com/duckdblabs/duckdb-internal/issues/6182 |
| 66 | + """ |
| 67 | + outcome = yield |
| 68 | + result = outcome.get_result() |
| 69 | + |
| 70 | + if sys.version_info[:2] == (3, 14): |
| 71 | + # Only handle failures from module collectors |
| 72 | + if result.failed and collector.__class__.__name__ == "Module": |
| 73 | + longrepr = str(result.longrepr) |
| 74 | + if "ModuleNotFoundError: No module named 'pyarrow'" in longrepr: |
| 75 | + result.outcome = "skipped" |
| 76 | + result.longrepr = f"XFAIL: pyarrow not available {collector.name} ({longrepr.strip()})" |
| 77 | + |
| 78 | + |
38 | 79 | # https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option |
39 | 80 | # https://stackoverflow.com/a/47700320 |
40 | 81 | def pytest_addoption(parser): |
|
0 commit comments