forked from equinor/ert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
29 lines (24 loc) · 861 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import pytest
@pytest.fixture()
def source_root():
path_list = os.path.dirname(os.path.abspath(__file__)).split("/")
while len(path_list) > 0:
git_path = os.path.join(os.sep, "/".join(path_list), ".git")
if os.path.isdir(git_path):
return os.path.join(os.sep, *path_list)
path_list.pop()
raise RuntimeError("Cannot find the source folder")
@pytest.fixture(autouse=True)
def env_save():
environment_pre = [
(key, val) for key, val in os.environ.items() if key != "PYTEST_CURRENT_TEST"
]
yield
environment_post = [
(key, val) for key, val in os.environ.items() if key != "PYTEST_CURRENT_TEST"
]
if set(environment_pre) != set(environment_post):
raise EnvironmentError(
"Your environment has changed after that test, please reset"
)