ResInsight/ApplicationCode/GrpcInterface/Python/rips/tests/conftest.py

42 lines
1.2 KiB
Python
Raw Normal View History

import pytest
import sys
import os
import getopt
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
_rips_instance = None
2019-06-04 13:35:30 -05:00
@pytest.fixture
def rips_instance():
return _rips_instance
2019-06-04 13:35:30 -05:00
@pytest.fixture
2019-09-19 06:25:04 -05:00
def initialize_test():
_rips_instance.project.close() # make sure ResInsight is clean before execution of test
2019-09-19 06:25:04 -05:00
yield initialize_test
_rips_instance.project.close() # make sure ResInsight is clean after test
def pytest_addoption(parser):
parser.addoption("--console", action="store_true", default=False, help="Run as console application")
parser.addoption("--existing", action="store_true", default=False, help="Look for existing ResInsight")
2019-06-04 13:35:30 -05:00
def pytest_configure(config):
global _rips_instance
console = False
if config.getoption('--existing'):
print("Looking for existing ResInsight")
_rips_instance = rips.Instance.find()
else:
if config.getoption('--console'):
console = True
_rips_instance = rips.Instance.launch(console=console)
if not _rips_instance:
print("Need a valid ResInsight executable to launch tests")
exit(0)
def pytest_unconfigure(config):
if not config.getoption('--existing'):
_rips_instance.exit()