11from __future__ import annotations
22
3+ import shutil
4+ import tempfile
5+ from pathlib import Path
36from typing import TYPE_CHECKING
47
58import pytest
1013from infrahub .core .manager import NodeManager
1114from infrahub .core .node import Node
1215from infrahub .services .adapters .cache .redis import RedisCache
16+ from infrahub .utils import get_fixtures_dir
1317from tests .constants import TestKind
1418from tests .helpers .file_repo import FileRepo
1519from tests .helpers .schema import CAR_SCHEMA , load_schema
1620from tests .helpers .test_app import TestInfrahubApp
1721
1822if TYPE_CHECKING :
19- from pathlib import Path
20-
2123 from infrahub_sdk import InfrahubClient
2224
2325 from infrahub .database import InfrahubDatabase
2426 from tests .adapters .message_bus import BusSimulator
2527
2628
2729class TestProposedChangePipelineConflict (TestInfrahubApp ):
30+ @pytest .fixture (scope = "class" )
31+ def car_dealership_copy (self ):
32+ """
33+ Copies car-dealership local repository to a temporary folder, with a new name.
34+ This is needed for this test as using car-dealership folder leads to issues most probably
35+ related to https://github.com/opsmill/infrahub/issues/4296 as some other tests use this same repository.
36+ """
37+
38+ source_folder = Path (get_fixtures_dir (), "repos" , "car-dealership" )
39+ new_folder_name = "car-dealership-copy"
40+
41+ with tempfile .TemporaryDirectory () as temp_dir :
42+ temp_path = Path (temp_dir )
43+ destination_folder = temp_path / new_folder_name
44+ shutil .copytree (source_folder , destination_folder )
45+ yield temp_path , new_folder_name
46+
2847 @pytest .fixture (scope = "class" )
2948 async def initial_dataset (
3049 self ,
@@ -33,6 +52,7 @@ async def initial_dataset(
3352 git_repos_source_dir_module_scope : Path ,
3453 client : InfrahubClient ,
3554 bus_simulator : BusSimulator ,
55+ car_dealership_copy : tuple [Path , str ],
3656 ) -> str :
3757 await load_schema (db , schema = CAR_SCHEMA )
3858 john = await Node .init (schema = TestKind .PERSON , db = db )
@@ -57,10 +77,11 @@ async def initial_dataset(
5777 await jesko .save (db = db )
5878
5979 bus_simulator .service .cache = RedisCache ()
60- FileRepo (name = "car-dealership" , sources_directory = git_repos_source_dir_module_scope )
80+ repo_path , repo_name = car_dealership_copy
81+ FileRepo (name = repo_name , local_repo_base_path = repo_path , sources_directory = git_repos_source_dir_module_scope )
6182 client_repository = await client .create (
6283 kind = InfrahubKind .REPOSITORY ,
63- data = {"name" : "car- dealership" , "location" : f"{ git_repos_source_dir_module_scope } /car-dealership " },
84+ data = {"name" : "dealership-car " , "location" : f"{ git_repos_source_dir_module_scope } /{ repo_name } " },
6485 )
6586 await client_repository .save ()
6687 return client_repository .id
0 commit comments