Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@


@pytest.fixture
def base_url():
return 'http://localhost/api/v2'
def base_url(alfalfa_host: str):
return f'{alfalfa_host}/api/v2'


@pytest.fixture
def alfalfa_client():
return AlfalfaClient()
def alfalfa_client(alfalfa_host: str):
return AlfalfaClient(host=alfalfa_host)


@pytest.fixture
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ def mock_dispatcher(tmp_path: Path):
work_dir.mkdir()
dispatcher = MockDispatcher(work_dir)
yield dispatcher


def pytest_addoption(parser):
parser.addoption("--host", action="store", default="http://localhost")


@pytest.fixture
def alfalfa_host(pytestconfig: pytest.Config):
alfalfa_host = pytestconfig.getoption("host")
if isinstance(alfalfa_host, str):
alfalfa_host.rstrip('/')
return alfalfa_host
14 changes: 2 additions & 12 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Consider factoring this out of the test file
import os
import shutil
import tempfile
from pathlib import Path

import pytest
Expand Down Expand Up @@ -38,8 +36,8 @@ def pytest_generate_tests(metafunc):


@pytest.fixture
def alfalfa():
client = AlfalfaClient(host="http://localhost")
def alfalfa(alfalfa_host: str):
client = AlfalfaClient(host=alfalfa_host)
yield client


Expand All @@ -53,14 +51,6 @@ def ref_id(model_path: Path, alfalfa: AlfalfaClient):
alfalfa.stop()


def create_zip(model_dir):
zip_file_fd, zip_file_path = tempfile.mkstemp(suffix='.zip')
zip_file_path = Path(zip_file_path)
shutil.make_archive(zip_file_path.parent / zip_file_path.stem, "zip", model_dir)

return zip_file_path


def prepare_model(model_path):
model_path = Path(__file__).parents[0] / 'models' / model_path
return str(model_path)
3 changes: 1 addition & 2 deletions tests/integration/test_broken_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


@pytest.mark.integration
def test_broken_models(broken_model_path):
alfalfa = AlfalfaClient(host='http://localhost')
def test_broken_models(broken_model_path, alfalfa: AlfalfaClient):
with pytest.raises(AlfalfaException):
run_id = alfalfa.submit(str(broken_model_path))
alfalfa.start(
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/test_schedule_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def test_schedule_point_generation(alfalfa: AlfalfaClient):


@pytest.mark.integration
def test_schedule_override():
alfalfa = AlfalfaClient('http://localhost')
def test_schedule_override(alfalfa: AlfalfaClient):
site_id = alfalfa.submit(prepare_model('schedule_model'))

alfalfa.start(
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_small_office_osw.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@


@pytest.mark.integration
def test_python_environment():
def test_python_environment(alfalfa: AlfalfaClient):
zip_file_path = prepare_model('small_office')
alfalfa = AlfalfaClient(host='http://localhost')
model_id = alfalfa.submit(zip_file_path)

alfalfa.wait(model_id, "ready")
Expand All @@ -31,7 +30,7 @@ def test_python_environment():


@pytest.mark.integration
def test_io(alfalfa: AlfalfaClient):
def test_io_enable_disable(alfalfa: AlfalfaClient):
zip_file_path = prepare_model('small_office')
site_id = alfalfa.submit(zip_file_path)

Expand Down
Loading