1 # Copyright 2024 highstreet technologies
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # inspired by https://github.com/rochacbruno/python-project-template
19 from typing import Any, Generator
23 @pytest.fixture(autouse=True)
24 def get_path_name(request: pytest.FixtureRequest) -> str:
25 return os.path.dirname(os.path.abspath(request.path.name))
28 # each test runs on cwd to its temp dir
29 @pytest.fixture(autouse=True)
30 def go_to_tmpdir(request: pytest.FixtureRequest) -> Generator[None, Any, None]:
31 # Get the fixture dynamically by its name.
32 tmpdir = request.getfixturevalue("tmpdir")
33 # ensure local test created packages can be imported
34 sys.path.insert(0, str(tmpdir))
35 # Chdir only for the duration of the test.