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
|
"""
unit-tests helpers
"""
import os
from platform import python_version
from pkg_resources import parse_version
from contextlib import contextmanager
import pytest
def skip_on_python_older_than(minimal_version, message, condition=None):
"""
Raise the "skip" exception if python doesn't match the minimal required
version for the calling test case
"""
if condition is not None and not condition:
return
if parse_version(python_version()) < parse_version(minimal_version):
generic_msg = "Python {0} required, have {1}".format(
minimal_version,
python_version(),
)
raise pytest.skip("{0} ({1})".format(message, generic_msg))
@contextmanager
def pushd(path):
old_dir = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(old_dir)
|