"""Load the model under test. pytest uses bracket.py unless told another file:
    pytest --model flawed/answer_1.py
"""
import importlib.util
import pathlib
import pytest


def pytest_addoption(parser):
    parser.addoption("--model", default="bracket.py", help="the model file to test")


@pytest.fixture(scope="session")
def model(request):
    path = pathlib.Path(request.config.getoption("--model")).resolve()
    if not path.exists():
        pytest.fail(f"no model yet: {path.name}", pytrace=False)
    spec = importlib.util.spec_from_file_location("model_under_test", path)
    mod = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(mod)
    return mod


@pytest.fixture(scope="session")
def part(model):
    return model.make_bracket()
