Fix #173 - Require gym-pusht to be installed for test_examples_3_and_2 (#174)

This commit is contained in:
Simon Alibert
2024-05-12 08:08:59 +02:00
committed by GitHub
parent ced3de4c94
commit 29a196c5dd
3 changed files with 53 additions and 1 deletions

View File

@@ -3,6 +3,8 @@ import subprocess
import sys
from pathlib import Path
from tests.utils import require_package
def _find_and_replace(text: str, finds_and_replaces: list[tuple[str, str]]) -> str:
for f, r in finds_and_replaces:
@@ -21,6 +23,7 @@ def test_example_1():
assert Path("outputs/examples/1_load_lerobot_dataset/episode_0.mp4").exists()
@require_package("gym_pusht")
def test_examples_3_and_2():
"""
Train a model with example 3, check the outputs.

View File

@@ -1,4 +1,5 @@
import platform
from functools import wraps
import pytest
import torch
@@ -61,7 +62,6 @@ def require_env(func):
Decorator that skips the test if the required environment package is not installed.
As it need 'env_name' in args, it also checks whether it is provided as an argument.
"""
from functools import wraps
@wraps(func)
def wrapper(*args, **kwargs):
@@ -82,3 +82,20 @@ def require_env(func):
return func(*args, **kwargs)
return wrapper
def require_package(package_name):
"""
Decorator that skips the test if the specified package is not installed.
"""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
if not is_package_available(package_name):
pytest.skip(f"{package_name} not installed")
return func(*args, **kwargs)
return wrapper
return decorator