-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgreenboard_fixture.py
More file actions
77 lines (68 loc) · 3.05 KB
/
greenboard_fixture.py
File metadata and controls
77 lines (68 loc) · 3.05 KB
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
import pytest
import pytest_asyncio
from cbltest import CBLPyTest
from cbltest.api.syncgateway import CouchbaseVersion
from cbltest.greenboarduploader import GreenboardUploader
from cbltest.logging import cbl_info, cbl_warning
# This plugin provides an automatic (i.e. not used directly by tests)
# fixture that will upload test results to greenboard, if it is
# properly set up in config.json (see the schema for that file)
# and if the --no-result-upload flag is not set on the command line.
@pytest_asyncio.fixture(scope="session", autouse=True)
async def greenboard(cblpytest: CBLPyTest, pytestconfig: pytest.Config):
if (
cblpytest.config.greenboard_username is None
or cblpytest.config.greenboard_password is None
or cblpytest.config.greenboard_url is None
):
yield
return
if pytestconfig.getoption("--no-result-upload"):
cbl_info("Greenboard uploading disabled by flag")
yield
return
if len(cblpytest.test_servers) == 0 and len(cblpytest.sync_gateways) == 0:
yield
return
uploader = GreenboardUploader(
cblpytest.config.greenboard_url,
cblpytest.config.greenboard_username,
cblpytest.config.greenboard_password,
)
pytestconfig.pluginmanager.register(uploader)
# This is a pytest-ism. You may have noticed it in other tests. The
# way that fixtures work is that you can yield in the middle and what
# ends up happening is that all other things happening within the scope
# will happen, and then return back to this point. Since the scope here
# is 'session' it basically means "before and after the run"
yield
try:
sgw_version: CouchbaseVersion | None = None
test_platform: str = "sync-gateway"
os_name: str = "n/a"
library_version: str = "n/a"
if len(cblpytest.test_servers) > 0:
test_server_info = await cblpytest.test_servers[0].get_info()
# Keep the platform as SGW if it has one of the sgw markers, since
# the test might still use test server with it, but still belong
# to SGW and not CBL test platform.
library_version = test_server_info.library_version
if not uploader.has_sgw_marker():
test_platform = test_server_info.cbl
if "systemName" in test_server_info.device:
os_name = test_server_info.device["systemName"]
if len(cblpytest.sync_gateways) > 0:
sgw_version = await cblpytest.sync_gateways[0].get_version()
uploader.upload(test_platform, os_name, library_version, sgw_version)
except Exception as e:
cbl_warning(f"Failed to upload results to Greenboard: {e}")
finally:
pytestconfig.pluginmanager.unregister(uploader)
# This adds the --no-result-upload option to the pytest command line.
def pytest_addoption(parser: pytest.Parser) -> None:
group = parser.getgroup("CBL E2E Testing")
group.addoption(
"--no-result-upload",
action="store_true",
help="Don't upload results to greenboard",
)