Create python environment for oam
[oam.git] / code / network-generator / tests / conftest.py
1 # Copyright 2023 highstreet technologies GmbH
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # inspired by https://github.com/rochacbruno/python-project-template
16
17 import os
18 import sys
19 from typing import Any, Generator
20 import pytest
21
22
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))
26
27
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.
36     with tmpdir.as_cwd():
37         yield