From 7be580c7f25e1c76da8bb60e799131951bf53689 Mon Sep 17 00:00:00 2001 From: Daniel Valent Date: Wed, 13 Sep 2023 11:34:17 +0200 Subject: [PATCH] SIMPLE-5780 replace change test dir fixture (#54) * SIMPLE-5780 replaced change_test_dir with test_dir --- conftest.py | 9 +++------ tests/conftest.py | 5 +++-- tests/test_client_library.py | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/conftest.py b/conftest.py index 3bc355f..d0cbca0 100644 --- a/conftest.py +++ b/conftest.py @@ -21,8 +21,7 @@ from __future__ import annotations -import os -from typing import Iterator +from pathlib import Path import pytest @@ -48,7 +47,5 @@ def pytest_addoption( @pytest.fixture -def change_test_dir(request: pytest.FixtureRequest) -> Iterator[None]: - os.chdir(request.path.parent) - yield - os.chdir(request.config.invocation_dir) +def test_dir(request: pytest.FixtureRequest) -> Path: + return request.path.parent diff --git a/tests/conftest.py b/tests/conftest.py index 48d4f3c..12e73f9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -84,7 +84,8 @@ def resp_body_from_file(request: httpx.Request) -> httpx.Response: elif endpoint_parts[0] == "labs": lab_id = endpoint_parts[1] filename = "_".join(endpoint_parts[2:]) + "-" + lab_id + ".json" - file_path = Path("test_data", filename) + test_dir = Path(__file__).parent.resolve() + file_path = test_dir / "test_data" / filename return httpx.Response(200, text=file_path.read_text()) @@ -141,6 +142,6 @@ def respx_mock_with_labs(respx_mock): @pytest.fixture -def client_library(respx_mock_with_labs, change_test_dir): +def client_library(respx_mock_with_labs): client = ClientLibrary(url=FAKE_HOST, username="test", password="pa$$") yield client diff --git a/tests/test_client_library.py b/tests/test_client_library.py index f43ebe0..c09c65a 100644 --- a/tests/test_client_library.py +++ b/tests/test_client_library.py @@ -713,12 +713,12 @@ def test_different_version_strings(): def test_import_lab_offline( - change_test_dir, client_library_server_current, mocked_session, tmp_path: Path + client_library_server_current, mocked_session, tmp_path: Path, test_dir ): client_library = ClientLibrary( url="https://0.0.0.0/fake_url/", username="test", password="pa$$" ) - topology_file_path = "test_data/sample_topology.json" + topology_file_path = test_dir / "test_data/sample_topology.json" with open(topology_file_path) as fh: topology_file = fh.read() client_library.import_lab(topology_file, "topology-v0_0_4", offline=True)