-
Notifications
You must be signed in to change notification settings - Fork 192
Integration with ReportPortal
ReportPortal services are mainly used for analyzing test results. We integrate report analysis into our framework, which collects and stores test log information and screenshot images in the Report Portal.
To run the automated test with ReportPortal you have to provide the ReportPortal api_key, endpoint, project name and launch. Refer env_conf file available at root of our repo and you can rename it to .env. ReportPortal api_key and endpoint can be taken from your ReportPortal profile. If you are a Qxf2 employee please ask your colleagues for these values.
report_portal_api_key = "Your-report-portal-api_key"
report_portal_endpoint = "Your-report-portal-endpoint"
Refer to our post if you are new to Reportportal. To attach info and screenshots refer this.
We configured pytest to run tests on ReportPortal by providing hooks and fixtures . These are stored in conftest.py file as shown below.
@pytest.hookimpl()
def pytest_configure(config):
"Sets the launch name based on the marker selected."
global if_reportportal
if_reportportal =config.getoption('--reportportal')
try:
config._inicache["rp_api_key"] = os.getenv('report_portal_api_key')
config._inicache["rp_endpoint"]= os.getenv('report_portal_endpoint')
config._inicache["rp_project"]=os.getenv('report_portal_project')
config._inicache["rp_launch"]=os.getenv('report_portal_launch')
except Exception as e:
print("Exception when trying to run test: %s"%__file__)
print("Python says:%s"%str(e))
#Registering custom markers to supress warnings
config.addinivalue_line("markers", "GUI: mark a test as part of the GUI regression suite.")
config.addinivalue_line("markers", "API: mark a test as part of the GUI regression suite.")
config.addinivalue_line("markers", "MOBILE: mark a test as part of the GUI regression suite.")
@pytest.fixture
def reportportal_service(request):
"pytest service fixture for reportportal"
reportportal_pytest_service = None
try:
if request.config.getoption("--reportportal"):
reportportal_pytest_service = request.node.config.py_test_service
except Exception as e:
print("Exception when trying to run test: %s"%__file__)
print("Python says:%s"%str(e))
solution = "It looks like you are trying to use report portal to run your test. \nPlease make sure you have updated .env with the right credentials ."
print('\033[92m'+"\nSOLUTION: %s\n"%solution+'\033[0m')
return reportportal_pytest_service
In conftest.py in pytest_addoption add these below lines
parser.addini("rp_api_key",'help',type="pathlist")
parser.addini("rp_endpoint",'help',type="pathlist")
parser.addini("rp_project",'help',type="pathlist")
parser.addini("rp_launch",'help',type="pathlist")
When the pytest sees the ReportPortal in test parameter, it connects with ReportPortal with our api_key, endpoints, project and Launch. We set the ReportPortal service object if we run with --reportportal
. If the ReportPortal service is true then we set up the rp_logger object.
To run pytest with reportportal: pytest -k example --reportportal