forked from oamg/leapp-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
74 lines (65 loc) · 2.69 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import logging
import os
from leapp.repository.scan import find_and_scan_repositories
from leapp.utils.repository import find_repository_basedir
logger = logging.getLogger(__name__)
logging.getLogger("asyncio").setLevel(logging.INFO)
logging.getLogger("parso").setLevel(logging.INFO)
def pytest_collectstart(collector):
if collector.nodeid:
current_repo_basedir = find_repository_basedir(collector.nodeid)
# loading the current repo
if (
not hasattr(collector.session, "leapp_repository")
or current_repo_basedir != collector.session.repo_base_dir
):
repo = find_and_scan_repositories(
find_repository_basedir(collector.nodeid), include_locals=True
)
repo.load(skip_actors_discovery=True)
collector.session.leapp_repository = repo
collector.session.repo_base_dir = current_repo_basedir
# we're forcing the actor context switch only when traversing new
# actor
if "/actors/" in str(collector.fspath) and (
not hasattr(collector.session, "current_actor_path")
or collector.session.current_actor_path + os.sep
not in str(collector.fspath)
):
actor = None
for a in collector.session.leapp_repository.actors:
if a.full_path == collector.fspath.dirpath().dirname:
actor = a
break
if not actor:
logger.info("No actor found, exiting collection...")
return
# we need to tear down the context from the previous
# actor
try:
collector.session.current_actor_context.__exit__(
None, None, None
)
except AttributeError:
pass
else:
logger.info(
"Actor %r context teardown complete",
collector.session.current_actor.name,
)
logger.info("Injecting actor context for %r", actor.name)
collector.session.current_actor = actor
collector.session.current_actor_context = actor.injected_context()
collector.session.current_actor_context.__enter__()
collector.session.current_actor_path = (
collector.session.current_actor.full_path
)
logger.info("Actor %r context injected", actor.name)
def pytest_runtestloop(session):
try:
session.current_actor_context.__exit__(None, None, None)
logger.info(
"Actor %r context teardown complete", session.current_actor.name,
)
except AttributeError:
pass