mirror of
https://github.com/bendtherules/pytest_gui_status.git
synced 2026-08-18 13:42:26 +00:00
add plugin test to check intermediate steps
still need to move them to folder such that pytest tracks it automatically
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
Todo
|
||||
------
|
||||
1. (--move tests to correct folder) check intermediate test steps like collect, testrun
|
||||
2. Add gui tests
|
||||
3. use logging.debug for more prints
|
||||
4. Allow config for tmpl, redis_arg, status_gui_arg
|
||||
5. Use config.pluginmanager.hasplugin('plugin_name')
|
||||
|
||||
1. move rendering update to js using diff-dom + nunjucks ( to be decided )
|
||||
2. (-done manually, add tests)check intermediate test steps like collect, testrun
|
||||
3. In plugin, set attributes in chunk using pipeline, using `with`
|
||||
4. Add gui tests
|
||||
5. use logging.debug for more prints
|
||||
6. Think about popen stdouts
|
||||
7. Print redis not connected in gui itself instead of console
|
||||
8. Allow config for tmpl, redis_arg, status_gui_arg
|
||||
|
||||
Done
|
||||
------
|
||||
@@ -20,3 +17,16 @@ Done
|
||||
5. (-) use pipelines when possible
|
||||
6. (---) Self Tests also pop up gui, add option for plugin
|
||||
9. (---) Register as pytest plugin in setup.py
|
||||
|
||||
|
||||
Think
|
||||
-------
|
||||
1. move rendering update to js using diff-dom + nunjucks ( to be decided )
|
||||
2. Think about popen stdouts
|
||||
|
||||
|
||||
Discarded
|
||||
----------
|
||||
|
||||
1. Show "redis not connected" in gui itself instead of console
|
||||
2. In plugin, set attributes in chunk using pipeline, using `with`
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# pytest_plugins = "pytest_gui_status.status_plugin"
|
||||
|
||||
import redis
|
||||
import pytest
|
||||
from pytest_gui_status.status_plugin.plugin import REDIS_PORT
|
||||
|
||||
|
||||
class PYTEST_DATA(object):
|
||||
data = {}
|
||||
|
||||
saved_data = {
|
||||
"after_sessionstart": None,
|
||||
"after_first_collectstart": None,
|
||||
"after_last_itemcollected": None,
|
||||
"after_first_runtest_logstart": None,
|
||||
"after_this_runtest_logstart": None,
|
||||
}
|
||||
|
||||
|
||||
def get_cur_data():
|
||||
|
||||
dir_name = PYTEST_DATA.data["dir_name_start"]
|
||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_PORT, db=0)
|
||||
hash_dir_name = redis_db.hget("directories_to_hash", dir_name)
|
||||
assert hash_dir_name is not None
|
||||
|
||||
data = {}
|
||||
|
||||
data["state"] = redis_db.get("{hash_a}_state".format(hash_a=hash_dir_name))
|
||||
data["last_updated"] = redis_db.get("{hash_a}_last_updated".format(hash_a=hash_dir_name))
|
||||
|
||||
data["collect"] = redis_db.lrange("{hash_a}_collect".format(hash_a=hash_dir_name), 0, -1)
|
||||
data["pass"] = redis_db.lrange("{hash_a}_pass".format(hash_a=hash_dir_name), 0, -1)
|
||||
data["fail"] = redis_db.lrange("{hash_a}_fail".format(hash_a=hash_dir_name), 0, -1)
|
||||
data["skip"] = redis_db.lrange("{hash_a}_skip".format(hash_a=hash_dir_name), 0, -1)
|
||||
|
||||
# strip off the filename
|
||||
data["collect"] = [item.split("::")[-1] for item in data["collect"]]
|
||||
data["pass"] = [item.split("::")[-1] for item in data["pass"]]
|
||||
data["fail"] = [item.split("::")[-1] for item in data["fail"]]
|
||||
data["skip"] = [item.split("::")[-1] for item in data["skip"]]
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@pytest.hookimpl(trylast=True)
|
||||
def pytest_sessionstart(session):
|
||||
PYTEST_DATA.data["dir_name_start"] = str(session.startdir)
|
||||
|
||||
saved_data["after_sessionstart"] = get_cur_data()
|
||||
|
||||
|
||||
@pytest.hookimpl(trylast=True)
|
||||
def pytest_collectstart(collector):
|
||||
if not saved_data["after_first_collectstart"]:
|
||||
saved_data["after_first_collectstart"] = get_cur_data()
|
||||
|
||||
|
||||
@pytest.hookimpl(trylast=True)
|
||||
def pytest_itemcollected(item):
|
||||
saved_data["after_last_itemcollected"] = get_cur_data()
|
||||
|
||||
|
||||
@pytest.hookimpl(trylast=True)
|
||||
def pytest_runtest_logstart(nodeid, location):
|
||||
if not saved_data["after_first_runtest_logstart"]:
|
||||
saved_data["after_first_runtest_logstart"] = get_cur_data()
|
||||
|
||||
saved_data["after_this_runtest_logstart"] = get_cur_data()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def status_plugin_debug():
|
||||
return saved_data
|
||||
@@ -0,0 +1,54 @@
|
||||
def test_after_sessionstart(status_plugin_debug):
|
||||
debug_data = status_plugin_debug["after_sessionstart"]
|
||||
|
||||
assert debug_data["collect"] == []
|
||||
assert debug_data["pass"] == []
|
||||
assert debug_data["fail"] == []
|
||||
assert debug_data["skip"] == []
|
||||
|
||||
assert debug_data["state"] == "start"
|
||||
|
||||
|
||||
def test_after_first_collectstart(status_plugin_debug):
|
||||
debug_data = status_plugin_debug["after_first_collectstart"]
|
||||
|
||||
assert debug_data["collect"] == []
|
||||
assert debug_data["pass"] == []
|
||||
assert debug_data["fail"] == []
|
||||
assert debug_data["skip"] == []
|
||||
|
||||
assert debug_data["state"] == "collect"
|
||||
|
||||
|
||||
def test_after_last_itemcollected(status_plugin_debug):
|
||||
debug_data = status_plugin_debug["after_last_itemcollected"]
|
||||
|
||||
# if the tests in this file change, adjust this list too
|
||||
assert debug_data["collect"] == ["test_after_sessionstart",
|
||||
"test_after_first_collectstart",
|
||||
"test_after_last_itemcollected",
|
||||
"test_after_first_runtest_logstart",
|
||||
"test_after_this_runtest_logstart"]
|
||||
assert debug_data["pass"] == []
|
||||
assert debug_data["fail"] == []
|
||||
assert debug_data["skip"] == []
|
||||
|
||||
assert debug_data["state"] == "collect"
|
||||
|
||||
|
||||
def test_after_first_runtest_logstart(status_plugin_debug):
|
||||
debug_data = status_plugin_debug["after_first_runtest_logstart"]
|
||||
|
||||
assert debug_data["pass"] == []
|
||||
assert debug_data["fail"] == []
|
||||
assert debug_data["skip"] == []
|
||||
|
||||
assert debug_data["state"] == "runtest"
|
||||
|
||||
|
||||
def test_after_this_runtest_logstart(status_plugin_debug):
|
||||
debug_data = status_plugin_debug["after_this_runtest_logstart"]
|
||||
|
||||
assert len(debug_data["pass"] + debug_data["fail"] + debug_data["skip"]) > 0
|
||||
|
||||
assert debug_data["state"] == "runtest"
|
||||
Reference in New Issue
Block a user