mirror of
https://github.com/bendtherules/pytest_gui_status.git
synced 2026-08-18 13:42:26 +00:00
Make gui executable and plugin func to call it on start
New requirement added: psutil - to check if pid is running on unix + windows plugin still doesnt start gui on start, test the func first
This commit is contained in:
@@ -8,37 +8,39 @@ import PyQt4.QtCore as QtCore
|
|||||||
from gui_backend import Controller
|
from gui_backend import Controller
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
def main():
|
||||||
dir_name_raw = sys.argv[1]
|
if len(sys.argv) > 1:
|
||||||
else:
|
dir_name_raw = sys.argv[1]
|
||||||
dir_name_raw = "."
|
else:
|
||||||
dir_name = os.path.abspath(dir_name_raw)
|
dir_name_raw = "."
|
||||||
|
dir_name = os.path.abspath(dir_name_raw)
|
||||||
|
|
||||||
# GUI initializations
|
# GUI initializations
|
||||||
app = htmlPy.AppGUI(title=u"{dir_name} - Test Status".format(dir_name=dir_name),
|
app = htmlPy.AppGUI(title=u"{dir_name} - Test Status".format(dir_name=dir_name),
|
||||||
developer_mode=True, width=150, height=80)
|
developer_mode=True, width=150, height=80)
|
||||||
app.window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
|
app.window.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
|
||||||
screen_geo = QApplication.desktop().availableGeometry()
|
screen_geo = QApplication.desktop().availableGeometry()
|
||||||
screen_topright = screen_geo.topRight()
|
screen_topright = screen_geo.topRight()
|
||||||
app.x_pos = (screen_topright.x() - 20) - app.width
|
app.x_pos = (screen_topright.x() - 20) - app.width
|
||||||
app.y_pos = (screen_topright.y() + 20)
|
app.y_pos = (screen_topright.y() + 20)
|
||||||
# import pdb;pdb.set_trace()
|
# import pdb;pdb.set_trace()
|
||||||
|
|
||||||
# GUI configarg
|
# GUI configarg
|
||||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||||
app.static_path = os.path.join(BASE_DIR, "static/")
|
app.static_path = os.path.join(BASE_DIR, "static/")
|
||||||
app.template_path = os.path.join(BASE_DIR, "tmpl/")
|
app.template_path = os.path.join(BASE_DIR, "tmpl/")
|
||||||
app.dir_name = dir_name
|
app.dir_name = dir_name
|
||||||
|
|
||||||
# Register back-end functionalities
|
# Register back-end functionalities
|
||||||
app_backend = Controller(app)
|
app_backend = Controller(app)
|
||||||
app.bind(app_backend)
|
app.bind(app_backend)
|
||||||
|
|
||||||
# GUI render config
|
# GUI render config
|
||||||
# app.html = u""
|
# app.html = u""
|
||||||
app_backend.redraw()
|
app_backend.redraw()
|
||||||
|
|
||||||
|
app.start()
|
||||||
|
|
||||||
# Start application
|
# Start application
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.start()
|
main()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import time
|
|||||||
import sys
|
import sys
|
||||||
import redis
|
import redis
|
||||||
import os
|
import os
|
||||||
|
import psutil
|
||||||
|
|
||||||
env_redis_port = os.environ.get("pytest_status_port")
|
env_redis_port = os.environ.get("pytest_status_port")
|
||||||
if env_redis_port:
|
if env_redis_port:
|
||||||
@@ -14,6 +15,8 @@ else:
|
|||||||
command_redis_server_gen = "redis-server --port {port} --maxheap 20MB"
|
command_redis_server_gen = "redis-server --port {port} --maxheap 20MB"
|
||||||
command_redis_server = command_redis_server_gen.format(port=REDIS_PORT)
|
command_redis_server = command_redis_server_gen.format(port=REDIS_PORT)
|
||||||
|
|
||||||
|
command_status_gui = "pytest_gui_status"
|
||||||
|
|
||||||
# Redis will look like:
|
# Redis will look like:
|
||||||
# PYTEST_STATUS_DB = 1
|
# PYTEST_STATUS_DB = 1
|
||||||
# directories_to_hash = {"dir_a":hash_a,"dir_b":hash_b}
|
# directories_to_hash = {"dir_a":hash_a,"dir_b":hash_b}
|
||||||
@@ -25,6 +28,7 @@ command_redis_server = command_redis_server_gen.format(port=REDIS_PORT)
|
|||||||
# {hash_a}_pass = [test_a_name,...]
|
# {hash_a}_pass = [test_a_name,...]
|
||||||
# {hash_a}_fail = [test_b_name,...]
|
# {hash_a}_fail = [test_b_name,...]
|
||||||
# {hash_a}_skip = [test_c_name,...]
|
# {hash_a}_skip = [test_c_name,...]
|
||||||
|
# {hash_a}_gui_pid = pid # check this before launching gui
|
||||||
|
|
||||||
|
|
||||||
class Helpers(object):
|
class Helpers(object):
|
||||||
@@ -70,11 +74,22 @@ class Helpers(object):
|
|||||||
# set last updated
|
# set last updated
|
||||||
Helpers.modify_last_updated(dir_name)
|
Helpers.modify_last_updated(dir_name)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def start_gui(dir_name):
|
||||||
|
# craete redis connection
|
||||||
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
||||||
|
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
||||||
|
|
||||||
|
existing_gui_pid = redis_db.get("{hash_a}_gui_pid".format(hash_a=hash_dir_name))
|
||||||
|
if (not existing_gui_pid) or (not psutil.pid_exists(existing_gui_pid)):
|
||||||
|
gui_popen_obj = subprocess.Popen(command_status_gui)
|
||||||
|
gui_pid = gui_popen_obj.pid
|
||||||
|
redis_db.set("{hash_a}_gui_pid".format(hash_a=hash_dir_name), gui_pid)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def on_collectstart(dir_name):
|
def on_collectstart(dir_name):
|
||||||
# craete redis connection
|
# craete redis connection
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
||||||
|
|
||||||
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
||||||
|
|
||||||
redis_db.set("{hash_a}_state".format(hash_a=hash_dir_name), "collect")
|
redis_db.set("{hash_a}_state".format(hash_a=hash_dir_name), "collect")
|
||||||
@@ -86,7 +101,6 @@ class Helpers(object):
|
|||||||
def on_collectend(dir_name, list_test_name):
|
def on_collectend(dir_name, list_test_name):
|
||||||
# craete redis connection
|
# craete redis connection
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
||||||
|
|
||||||
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
||||||
|
|
||||||
redis_db.rpush("{hash_a}_collect".format(hash_a=hash_dir_name), *list_test_name)
|
redis_db.rpush("{hash_a}_collect".format(hash_a=hash_dir_name), *list_test_name)
|
||||||
@@ -98,7 +112,6 @@ class Helpers(object):
|
|||||||
def on_test_eachstart(dir_name):
|
def on_test_eachstart(dir_name):
|
||||||
# craete redis connection
|
# craete redis connection
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
||||||
|
|
||||||
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
||||||
|
|
||||||
redis_db.set("{hash_a}_state".format(hash_a=hash_dir_name), "runtest")
|
redis_db.set("{hash_a}_state".format(hash_a=hash_dir_name), "runtest")
|
||||||
@@ -110,7 +123,6 @@ class Helpers(object):
|
|||||||
def on_test_eachend(dir_name, list_test_result):
|
def on_test_eachend(dir_name, list_test_result):
|
||||||
# craete redis connection
|
# craete redis connection
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
||||||
|
|
||||||
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
||||||
|
|
||||||
list_testname_pass = [test_result.nodeid for test_result in
|
list_testname_pass = [test_result.nodeid for test_result in
|
||||||
@@ -136,7 +148,6 @@ class Helpers(object):
|
|||||||
def on_end(dir_name):
|
def on_end(dir_name):
|
||||||
# craete redis connection
|
# craete redis connection
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
||||||
|
|
||||||
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
||||||
|
|
||||||
redis_db.set("{hash_a}_state".format(hash_a=hash_dir_name), "end")
|
redis_db.set("{hash_a}_state".format(hash_a=hash_dir_name), "end")
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
pytest
|
pytest
|
||||||
python-dateutil
|
python-dateutil
|
||||||
|
|
||||||
|
psutil
|
||||||
|
humanfriendly
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ package_dir = {
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pytest_gui_status',
|
name='pytest_gui_status',
|
||||||
version='0.0.2',
|
version='0.0.3',
|
||||||
description='Show pytest status in gui',
|
description='Show pytest status in gui',
|
||||||
author='Abhas Bhattacharya',
|
author='Abhas Bhattacharya',
|
||||||
author_email='abhasbhattacharya2@gmail.com',
|
author_email='abhasbhattacharya2@gmail.com',
|
||||||
@@ -26,6 +26,9 @@ setup(
|
|||||||
entry_points={
|
entry_points={
|
||||||
# 'pytest11': [
|
# 'pytest11': [
|
||||||
# 'pytest_gui_status = pytest_gui_status.main',
|
# 'pytest_gui_status = pytest_gui_status.main',
|
||||||
# ]
|
# ],
|
||||||
|
'console_scripts': [
|
||||||
|
'pytest_gui_status = pytest_gui_status.status_gui.gui_frontend:main',
|
||||||
|
]
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user