Например, учитывая необязательные зависимости, подобные этой, в pyproject.toml:
Код: Выделить всё
[project.optional-dependencies]
extra_name = ["package_name>=1.0"]
Код: Выделить всё
@skip_if_optionals_are_not_installed("extra_name")
def test_something():
# Test logic here
pass
Код: Выделить всё
import toml
from pathlib import Path
from functools import wraps
def __get_optional_requirements(module: str):
with Path("pyproject.toml").open() as file:
data = toml.load(file)
optional_requirements = data.get("project", {}).get("optional-dependencies", {})
return optional_requirements.get(module, [])
def requires_pip_optional_or_skip_test(optional_module_name):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
requirements = __get_optional_requirements(optional_module_name)
for requirement in requirements:
compare_versions(requirement) # Some function to check if the dependency is installed
return func(*args, **kwargs)
return wrapper
return decorator
Подробнее здесь: https://stackoverflow.com/questions/793 ... -installed
Мобильная версия