-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
88 lines (73 loc) · 2.08 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
# -*- 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 (or the app fixture).
"""
import logging
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):
"""
Display test method name in active window title bar
"""
global _widget
module, line, method = item.location
module = module.replace('.py', '.')
title = module + method
widgets = QApplication.instance().topLevelWidgets()
for w in widgets:
w.setWindowTitle(title)
logging.info("------------------- %s -------------------", title)
# -------------------
# Setup logging
# -------------------
logging.basicConfig(level=logging.DEBUG,
filename='pytest.log',
filemode='w')
# -------------------
# Setup QApplication
# -------------------
# 2. create qt application
_app = QApplication(sys.argv)
_widget = None
# -------------------
# Session fixtures
# -------------------
@pytest.fixture(scope="session")
def app(request):
global _app
return app
@pytest.fixture()
def editor(request):
global _app, _widget
from pyqode.core import modes
from pyqode.json.widgets import JSONCodeEdit
from pyqode.qt.QtTest import QTest
logging.info('################ setup session editor ################')
_widget = JSONCodeEdit()
_widget.resize(800, 600)
_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
_widget.close()
while _widget.backend.connected:
QTest.qWait(100)
del _widget
request.addfinalizer(fin)
return _widget