diff --git a/openapi_python_client/config.py b/openapi_python_client/config.py index a246b3737..ace95c6b1 100644 --- a/openapi_python_client/config.py +++ b/openapi_python_client/config.py @@ -37,7 +37,7 @@ class Config(BaseModel): @staticmethod def load_from_path(path: Path) -> "Config": """Creates a Config from provided JSON or YAML file and sets a bunch of globals from it""" - mime = mimetypes.guess_type(path.as_uri(), strict=True)[0] + mime = mimetypes.guess_type(path.absolute().as_uri(), strict=True)[0] if mime == "application/json": config_data = json.loads(path.read_text()) else: diff --git a/pyproject.toml b/pyproject.toml index e136c3eb9..0bc30d05b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,8 @@ isort .\ && poetry export -f requirements.txt | poetry run safety check --bare --stdin\ && mypy openapi_python_client\ && pylint openapi_python_client\ - && pytest --cov openapi_python_client tests --cov-report=term-missing\ + && TASKIPY=true pytest --cov openapi_python_client tests --cov-report=term-missing --basetemp=tests/tmp\ + && rm -r tests/tmp\ """ regen = "python -m end_to_end_tests.regen_golden_record" e2e = "pytest openapi_python_client end_to_end_tests/test_end_to_end.py" diff --git a/tests/test_config.py b/tests/test_config.py index 56407f744..95c3d948d 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,6 @@ import json +import os +from pathlib import Path import pytest import yaml @@ -19,8 +21,14 @@ def json_with_tabs(d): ("example.json", json_with_tabs), ], ) -def test_load_from_path(tmp_path, filename, dump): +@pytest.mark.parametrize("relative", (True, False), ids=("relative", "absolute")) +def test_load_from_path(tmp_path: Path, filename, dump, relative): yml_file = tmp_path.joinpath(filename) + if relative: + if not os.getenv("TASKIPY"): + pytest.skip("Only test relative paths when running with `task check`") + return + yml_file = yml_file.relative_to(Path.cwd()) override1 = {"class_name": "ExampleClass", "module_name": "example_module"} override2 = {"class_name": "DifferentClass", "module_name": "different_module"} data = {