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

Code before:
        parser.addoption("--vis", action="store_true", default=False, help="Enable interactive viewer.")
    parser.addoption("--dev", action="store_true", default=False, help="Enable genesis debug mode.")
    supported, _reason = is_mem_monitoring_supported()
    help_text = (
        "Run memory monitoring, and store results to mem_monitoring_filepath. CUDA on linux ONLY."
        if supported
        else SUPPRESS
    )
    parser.addoption("--mem-monitoring-filepath", type=str, help=help_text)
    if os.environ.get("GS_PROFILING", "0") == "1":
        profiling.parser_add_options(parser)


@pytest.fixture(scope="session")
def show_viewer(pytestconfig):
    return pytestconfig.getoption("--vis", IS_INTERACTIVE_VIEWER_AVAILABLE)


@pytest.fixture(scope="session")
def pytorch_profiler(pytestconfig):
    if os.environ.get("GS_PROFILING", "0") == "1":
        for res in profiling.pytorch_profiler(pytestconfig):
            yield res
    else:
        noop = lambda: None  # noqa: E731
        yield None, noop


@pytest.fixture(scope="session")
def backend(pytestconfig):
    return pytestconfig.getoption("--backend") or "cpu"


@pytest.fixture(scope="session")
def asset_tmp_path(tmp_path_factory):
    return tmp_path_factory.mktemp("assets")


@pytest.fixture
def tol():
    import numpy as np
    import genesis as gs

    return TOL_DOUBLE if gs.np_float == np.float64 else TOL_SINGLE


@pytest.fixture
def precision(request, backend):
    import genesis as gs

    precision = None

Review comment (suggestion):
Use nullcontext; See `examples/speed_benchmark/timers.py`

Code after:
        parser.addoption("--vis", action="store_true", default=False, help="Enable interactive viewer.")
    parser.addoption("--dev", action="store_true", default=False, help="Enable genesis debug mode.")
    supported, _reason = is_mem_monitoring_supported()
    help_text = (
        "Run memory monitoring, and store results to mem_monitoring_filepath. CUDA on linux ONLY."
        if supported
        else SUPPRESS
    )
    parser.addoption("--mem-monitoring-filepath", type=str, help=help_text)
    if os.environ.get("GS_PROFILING", "0") == "1":
        profiling.parser_add_options(parser)


# Note: moving this out of conftest.py, e.g. into profiling.py, does not appear to work.
@pytest.fixture(scope="session")
def pytorch_profiler_step(pytestconfig):
    if os.environ.get("GS_PROFILING", "0") == "1":
        for res in profiling.pytorch_profiler(pytestconfig):
            yield res
    else:
        noop = lambda: None  # noqa: E731
        yield noop


@pytest.fixture(scope="session")
def show_viewer(pytestconfig):
    return pytestconfig.getoption("--vis", IS_INTERACTIVE_VIEWER_AVAILABLE)


@pytest.fixture(scope="session")
def backend(pytestconfig):
    return pytestconfig.getoption("--backend") or "cpu"


@pytest.fixture(scope="session")
def asset_tmp_path(tmp_path_factory):
    return tmp_path_factory.mktemp("assets")


@pytest.fixture
def tol():
    import numpy as np
    import genesis as gs

    return TOL_DOUBLE if gs.np_float == np.float64 else TOL_SINGLE


@pytest.fixture
def precision(request, backend):
    import genesis as gs