Repository: Genesis-Embodied-AI/Genesis
File: tests/conftest.py (Python)

Code before:
# def pytest_runtest_setup(item):
#     # Include test name in process title
#     test_name = item.nodeid.replace(" ", "")
#     setproctitle.setproctitle(f"pytest: {test_name}")


def validate_mem_option() -> None:
    try:
        assert sys.platform.startswith("linux")
        nvidia_out = subprocess.check_output(["nvidia-smi"]).decode("utf-8")
    except Exception as e:
        print("--mem not supported on this platform", e)
        raise e


@pytest.hookimpl(tryfirst=True)
def pytest_cmdline_main(config: pytest.Config) -> None:
    # Make sure that no unsupported markers have been specified in CLI
    declared_markers = set(name for spec in config.getini("markers") if (name := spec.split(":")[0]) != "forked")
    try:
        eval(config.option.markexpr, {"__builtins__": {}}, {key: None for key in declared_markers})
    except NameError as e:
        raise pytest.UsageError(f"Unknown marker in CLI expression: '{e.name}'")

    # Only launch memory monitor from the main process, not from xdist workers
    if config.getoption("--mem-monitoring-filepath") and not os.environ.get("PYTEST_XDIST_WORKER"):
        validate_mem_option()
        subprocess.Popen(
            [
                sys.executable,
                "tests/monitor_test_mem.py",
                "--die-with-parent",
                "--out-csv-filepath",
                config.getoption("--mem-monitoring-filepath"),
            ]
        )

    # Make sure that benchmarks are running on GPU and the number of workers if valid
    expr = Expression.compile(config.option.markexpr)
    is_benchmarks = expr.evaluate(MarkMatcher.from_markers((pytest.mark.benchmarks,)))
    if is_benchmarks:
        # Make sure that GPU backend is enforced
        backend = config.getoption("--backend")
        if backend == "cpu":
            raise ValueError("Running benchmarks on CPU is not supported.")
        config.option.backend = "gpu"

    # Force disabling forked for non-linux systems
    if not sys.platform.startswith("linux"):
        config.option.forked = False


Review comment (suggestion):
If think you should check if xdist is enabled or not. If so, you can start it right away. If not, run this command in the main process. See what is done at the very end of the function for benchmarks.

Code after:

def pytest_make_parametrize_id(config, val, argname):
    if isinstance(val, Enum):
        return val.name
    if isinstance(val, type):
        return ".".join((val.__module__, val.__name__))
    return f"{val}"


@pytest.hookimpl(tryfirst=True)
def pytest_cmdline_main(config: pytest.Config) -> None:
    # Make sure that no unsupported markers have been specified in CLI
    declared_markers = set(name for spec in config.getini("markers") if (name := spec.split(":")[0]) != "forked")
    try:
        eval(config.option.markexpr, {"__builtins__": {}}, {key: None for key in declared_markers})
    except NameError as e:
        raise pytest.UsageError(f"Unknown marker in CLI expression: '{e.name}'")

    # Only launch memory monitor from the main process, not from xdist workers
    mem_filepath = config.getoption("--mem-monitoring-filepath")
    if mem_filepath and not os.environ.get("PYTEST_XDIST_WORKER"):
        supported, reason = is_mem_monitoring_supported()
        if not supported:
            raise pytest.UsageError(f"--mem-monitoring-filepath is not supported on this platform: {reason}")
        subprocess.Popen(
            [
                sys.executable,
                "tests/monitor_test_mem.py",
                "--die-with-parent",
                "--out-csv-filepath",
                mem_filepath,
            ]
        )

    # Make sure that benchmarks are running on GPU and the number of workers if valid
    expr = Expression.compile(config.option.markexpr)
    is_benchmarks = expr.evaluate(MarkMatcher.from_markers((pytest.mark.benchmarks,)))
    if is_benchmarks:
        # Make sure that GPU backend is enforced
        backend = config.getoption("--backend")
        if backend == "cpu":
            raise ValueError("Running benchmarks on CPU is not supported.")
        config.option.backend = "gpu"

    # Force disabling forked for non-linux systems
    if not sys.platform.startswith("linux"):
        config.option.forked = False

    # Force disabling distributed framework if interactive viewer is enabled
    show_viewer = config.getoption("--vis")
    if show_viewer: