-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
54 lines (36 loc) · 1.44 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import shutil
import sys
import tempfile
import pytest
# add
if "volttron" not in sys.path:
sys.path.insert(0, "volttron")
def create_volttron_home(monkeypatch) -> str:
"""
Creates a VOLTTRON_HOME temp directory for use within a testing context.
This function will return a string containing the VOLTTRON_HOME but will not
set the global variable.
:return: str: the temp directory
"""
volttron_home = tempfile.mkdtemp(prefix="/tmp/volttron_testing")
# This is needed to run tests with volttron's secure mode. Without this
# default permissions for folders under /tmp directory doesn't not have read or execute for group or others
os.chmod(volttron_home, 0o755)
# Move volttron_home to be one level below the mkdir so that
# the volttron.log file is not part of the same folder for
# observer.
volttron_home = os.path.join(volttron_home, "volttron_home")
os.makedirs(volttron_home)
monkeypatch.setenv("VOLTTRON_HOME", volttron_home)
return volttron_home
@pytest.fixture(scope="function")
def create_volttron_home_fun_scope(monkeypatch):
volttron_home = create_volttron_home(monkeypatch)
yield volttron_home
shutil.rmtree(volttron_home, ignore_errors=True)
@pytest.fixture(scope="module")
def create_volttron_home_mod_scope(monkeypatch):
volttron_home = create_volttron_home(monkeypatch)
yield volttron_home
shutil.rmtree(volttron_home, ignore_errors=True)