This repository was archived by the owner on Mar 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconftest.py
93 lines (75 loc) · 2.13 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
"""
This scripts configures the test suite. We do two things:
- setup the logging module
- create ONE SINGLE INSTANCE of QApplication:
this implies that you must use **QApplication.instance** in your
test scripts.
"""
import logging
import os
import sys
import pytest
from pyqode.qt.QtWidgets import QApplication
try:
import faulthandler
faulthandler.enable()
except ImportError:
pass
# -------------------
# Setup runtest
# -------------------
def pytest_runtest_setup(item):
"""
Logs test name into pytest.log
"""
if isinstance(item, item.Function):
logging.info("------------------- %s -------------------",
item.name)
# -------------------
# Setup logging
# -------------------
logging.basicConfig(level=logging.INFO,
filename='pytest.log',
filemode='w')
# -------------------
# Setup QApplication
# -------------------
# 2. create qt application
print('isinstanciating QApplication')
_app = QApplication(sys.argv)
_widget = None
# -------------------
# Session fixtures
# -------------------
@pytest.fixture(scope="session")
def app(request):
global _app
return app
@pytest.fixture(scope="session")
def editor(request):
import gettext
gettext.NullTranslations().install()
global _app, _widget
from pyqode.core import modes
from pyqode.cobol.widgets import CobolCodeEdit
from pyqode.qt.QtTest import QTest
logging.info('################ setup session editor ################')
_widget = CobolCodeEdit()
_widget.resize(800, 600)
_widget.show()
_app.setActiveWindow(_widget)
while not _widget.backend.connected:
QTest.qWait(100)
_widget.modes.get(modes.FileWatcherMode).file_watcher_auto_reload = True
_widget.save_on_focus_out = False
def fin():
global _widget
logging.info('################ teardown session editor ###############'
'#')
_widget.backend.stop()
while _widget.backend.connected:
QTest.qWait(100)
del _widget
request.addfinalizer(fin)
return _widget