2020-01-25 00:26:10 +00:00
|
|
|
from eth2spec.config import config_util
|
2020-01-04 17:33:15 +00:00
|
|
|
from eth2spec.test.context import reload_specs
|
2019-05-08 16:14:47 +00:00
|
|
|
|
2020-01-24 23:43:43 +00:00
|
|
|
|
2019-05-08 16:14:47 +00:00
|
|
|
# We import pytest only when it's present, i.e. when we are running tests.
|
|
|
|
# The test-cases themselves can be generated without installing pytest.
|
|
|
|
|
2019-05-30 01:53:46 +00:00
|
|
|
|
2019-05-08 16:14:47 +00:00
|
|
|
def module_exists(module_name):
|
|
|
|
try:
|
|
|
|
__import__(module_name)
|
|
|
|
except ImportError:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def fixture(*args, **kwargs):
|
|
|
|
if module_exists("pytest"):
|
|
|
|
import pytest
|
|
|
|
return pytest.fixture(*args, **kwargs)
|
|
|
|
else:
|
|
|
|
def ignore():
|
|
|
|
pass
|
|
|
|
return ignore
|
|
|
|
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption(
|
|
|
|
"--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@fixture(autouse=True)
|
|
|
|
def config(request):
|
|
|
|
config_name = request.config.getoption("--config")
|
2020-01-25 00:26:10 +00:00
|
|
|
config_util.prepare_config('../../../configs/', config_name)
|
2020-01-04 17:33:15 +00:00
|
|
|
# now that the presets are loaded, reload the specs to apply them
|
|
|
|
reload_specs()
|