22# and/or modify it under the terms of the GPL licence
33
44import logging
5- import cgi
6-
7- import pytest
85
96from .service import PyTestService
10-
11-
12- class RP_Report_Listener (object ):
13-
14- # Identifier if TestItem is called:
15- # if setup is failed, pytest will NOT call
16- # TestItem and Result will not reported!
17- called = None
18- # Test Item result
19- result = None
20-
21- @pytest .mark .hookwrapper
22- def pytest_runtest_makereport (self , item , call ):
23- report = (yield ).get_result ()
24-
25- if report .when == "setup" :
26- # when function pytest_setup is called,
27- # test item session will be started in RP
28- PyTestService .start_pytest_item (item )
29-
30- if report .longrepr :
31- PyTestService .post_log (
32- cgi .escape (report .longreprtext ),
33- loglevel = 'ERROR' ,
34- )
35-
36- if report .when == "call" :
37- self .called = True
38- if report .passed :
39- item_result = "PASSED"
40- elif report .failed :
41- item_result = "FAILED"
42- else :
43- item_result = "SKIPPED"
44-
45- self .result = item_result
46-
47- if report .when == "teardown" :
48- # If item is called, result of TestItem is reported
49- if self .called is True :
50- item_result = self .result
51- else :
52- # If setup - failed or skipped,
53- # the TestItem will reported as SKIPPED
54- item_result = "SKIPPED"
55- PyTestService .finish_pytest_item (item_result )
56- self .called = None
7+ from .listener import RPReportListener
578
589
5910def pytest_sessionstart (session ):
6011 PyTestService .init_service (
61- project = session .config .getini (" rp_project" ),
62- endpoint = session .config .getini (" rp_endpoint" ),
63- uuid = session .config .getini (" rp_uuid" ),
64- log_batch_size = int (session .config .getini (" rp_log_batch_size" )),
65- ignore_errors = bool (session .config .getini (" rp_ignore_errors" )),
66- ignored_tags = session .config .getini (" rp_ignore_tags" ),
12+ project = session .config .getini (' rp_project' ),
13+ endpoint = session .config .getini (' rp_endpoint' ),
14+ uuid = session .config .getini (' rp_uuid' ),
15+ log_batch_size = int (session .config .getini (' rp_log_batch_size' )),
16+ ignore_errors = bool (session .config .getini (' rp_ignore_errors' )),
17+ ignored_tags = session .config .getini (' rp_ignore_tags' ),
6718 )
6819
6920 PyTestService .start_launch (
7021 session .config .option .rp_launch ,
71- tags = session .config .getini (" rp_launch_tags" ),
72- description = session .config .getini (" rp_launch_description" ),
22+ tags = session .config .getini (' rp_launch_tags' ),
23+ description = session .config .getini (' rp_launch_description' ),
7324 )
7425
7526
76- def pytest_sessionfinish (session ):
27+ def pytest_sessionfinish ():
7728 # FixMe: currently method of RP api takes the string parameter
7829 # so it is hardcoded
79- PyTestService .finish_launch (status = " RP_Launch" )
30+ PyTestService .finish_launch (status = ' RP_Launch' )
8031
8132
8233def pytest_configure (config ):
8334 if not config .option .rp_launch :
84- config .option .rp_launch = config .getini (" rp_launch" )
35+ config .option .rp_launch = config .getini (' rp_launch' )
8536
8637 # set Pytest_Reporter and configure it
87- config ._reporter = RP_Report_Listener ()
38+ config ._reporter = RPReportListener ()
8839
89- if hasattr (config , " _reporter" ):
40+ if hasattr (config , ' _reporter' ):
9041 config .pluginmanager .register (config ._reporter )
9142
9243
9344def pytest_unconfigure (config ):
9445 PyTestService .terminate_service ()
9546
96- if hasattr (config , " _reporter" ):
47+ if hasattr (config , ' _reporter' ):
9748 reporter = config ._reporter
9849 del config ._reporter
9950 config .pluginmanager .unregister (reporter )
@@ -103,7 +54,7 @@ def pytest_unconfigure(config):
10354def pytest_addoption (parser ):
10455 group = parser .getgroup ("reporting" )
10556 group .addoption (
106- " --rp-launch" ,
57+ ' --rp-launch' ,
10758 action = "store" ,
10859 dest = "rp_launch" ,
10960 help = "Launch name (overrides rp_launch config option)" )
0 commit comments