2019-06-04 12:59:06 +02:00
|
|
|
import pytest
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
2019-06-05 15:45:22 +02:00
|
|
|
import getopt
|
2019-06-04 12:59:06 +02:00
|
|
|
|
2019-06-12 08:29:41 +02:00
|
|
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
2019-06-04 12:59:06 +02:00
|
|
|
import rips
|
|
|
|
|
|
2019-06-05 15:45:22 +02:00
|
|
|
_rips_instance = None
|
2019-06-04 20:35:30 +02:00
|
|
|
|
2020-04-16 16:06:18 +02:00
|
|
|
|
2019-06-04 12:59:06 +02:00
|
|
|
@pytest.fixture
|
|
|
|
|
def rips_instance():
|
2019-06-05 15:45:22 +02:00
|
|
|
return _rips_instance
|
2019-06-04 12:59:06 +02:00
|
|
|
|
2020-04-16 16:06:18 +02:00
|
|
|
|
2019-06-04 20:35:30 +02:00
|
|
|
@pytest.fixture
|
2019-09-19 13:25:04 +02:00
|
|
|
def initialize_test():
|
2020-04-16 16:06:18 +02:00
|
|
|
_rips_instance.project.close() # make sure ResInsight is clean before execution of test
|
2019-09-19 13:25:04 +02:00
|
|
|
yield initialize_test
|
2020-04-16 16:06:18 +02:00
|
|
|
_rips_instance.project.close() # make sure ResInsight is clean after test
|
|
|
|
|
|
2019-06-05 15:45:22 +02:00
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
2020-04-16 16:06:18 +02:00
|
|
|
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 20:35:30 +02:00
|
|
|
|
2019-06-05 15:45:22 +02:00
|
|
|
def pytest_configure(config):
|
|
|
|
|
global _rips_instance
|
|
|
|
|
console = False
|
2019-06-06 09:12:44 +02:00
|
|
|
if config.getoption('--existing'):
|
|
|
|
|
print("Looking for existing ResInsight")
|
|
|
|
|
_rips_instance = rips.Instance.find()
|
2019-06-06 09:13:23 +02:00
|
|
|
else:
|
|
|
|
|
if config.getoption('--console'):
|
|
|
|
|
console = True
|
2019-06-06 09:12:44 +02:00
|
|
|
_rips_instance = rips.Instance.launch(console=console)
|
|
|
|
|
if not _rips_instance:
|
|
|
|
|
print("Need a valid ResInsight executable to launch tests")
|
|
|
|
|
exit(0)
|
2019-06-06 13:48:59 +02:00
|
|
|
|
2020-04-16 16:06:18 +02:00
|
|
|
|
2019-07-30 11:55:13 +02:00
|
|
|
def pytest_unconfigure(config):
|
|
|
|
|
if not config.getoption('--existing'):
|
2020-12-18 16:02:50 +01:00
|
|
|
if _rips_instance:
|
|
|
|
|
_rips_instance.exit()
|