-
Notifications
You must be signed in to change notification settings - Fork 107
/
conftest.py
55 lines (42 loc) · 1.68 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
55
import json
import os
import shutil
from cli.src.Config import Config
from cli.src.schema.ManifestHandler import ManifestHandler
from cli.testing.helpers.constants import TEST_DOCS, CLUSTER_NAME_SAVE, CLUSTER_NAME_LOAD, NON_EXISTING_CLUSTER,\
TEST_JSON, TEST_JSON_NAME
def pytest_configure(config):
"""
Allows plugins and conftest files to perform initial configuration.
This hook is called for every plugin and initial conftest
file after command line options have been parsed.
"""
Config().output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_results/')
prepare_test_directory()
def pytest_sessionstart(session):
"""
Called after the Session object has been created and
before performing collection and entering the run test loop.
"""
def pytest_sessionfinish(session, exitstatus):
"""
Called after whole test run finished, right before
returning the exit status to the system.
"""
def pytest_unconfigure(config):
"""
called before test process is exited.
"""
def prepare_test_directory():
for path in [CLUSTER_NAME_LOAD, CLUSTER_NAME_SAVE, NON_EXISTING_CLUSTER, TEST_JSON_NAME]:
rm_existing(os.path.join(Config().output_dir, path))
prepare_test_data_for_load()
def prepare_test_data_for_load():
mhandler: ManifestHandler = ManifestHandler(cluster_name=CLUSTER_NAME_LOAD)
mhandler.update_docs(TEST_DOCS)
mhandler.write_manifest('manifest.yml')
with open(os.path.join(Config().output_dir, TEST_JSON_NAME), 'w') as out:
json.dump(TEST_JSON, out)
def rm_existing(path):
if os.path.exists(path):
shutil.rmtree(path) if os.path.isdir(path) else os.remove(path)