Skip to content

Commit

Permalink
SIMPLE-5780 replace change test dir fixture (#54)
Browse files Browse the repository at this point in the history
* SIMPLE-5780 replaced change_test_dir with test_dir
  • Loading branch information
daniel-valent authored Sep 13, 2023
1 parent 0efbaff commit 7be580c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
9 changes: 3 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

from __future__ import annotations

import os
from typing import Iterator
from pathlib import Path

import pytest

Expand All @@ -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
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())


Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/test_client_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7be580c

Please sign in to comment.