File size: 1,297 Bytes
18c4140
 
 
 
 
 
 
 
 
 
060f765
 
 
 
 
 
9470076
 
 
 
060f765
18c4140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Shared pytest collection guards for optional Rust-engine tests."""
from __future__ import annotations

import importlib.util
import inspect

import pytest


_ENGINE_SKIP = pytest.mark.skip(reason="Rust env wheel not installed")
_ENGINE_TOKENS = (
    "run_level(",
    "RustEnvPool(",
    "run_handoff(",
    "open_study_session(",
    "import openra_train",
    # Helper in tests/test_perception_ablation.py that boots a real
    # Rust env pool — the test bodies don't carry the explicit tokens
    # above, only this helper-call signature, so detect it directly.
    "_render_state(",
)


def pytest_collection_modifyitems(config, items):
    """Skip live Rust-engine tests when the openra_train wheel is absent.

    CI for this repo installs Python requirements but does not build the
    optional OpenRA-Rust extension. Structural/schema tests should still run;
    only tests that directly exercise the live engine via run_level or
    RustEnvPool are skipped.
    """
    if importlib.util.find_spec("openra_train") is not None:
        return
    for item in items:
        try:
            src = inspect.getsource(item.obj)
        except (OSError, TypeError):
            continue
        if any(token in src for token in _ENGINE_TOKENS):
            item.add_marker(_ENGINE_SKIP)