22# and/or modify it under the terms of the GPL licence
33
44import logging
5- import dill as pickle
6- import pytest
7- from .service import PyTestServiceClass
5+
6+ from .service import PyTestService
87from .listener import RPReportListener
98
109try :
1514 PYTEST_HAS_LOGGING_PLUGIN = False
1615
1716
18- def is_master (config ):
19- """
20- True if the code running the given pytest.config object is running in a xdist master
21- node or not running xdist at all.
22- """
23- return not hasattr (config , 'slaveinput' )
24-
25-
26- @pytest .mark .optionalhook
27- def pytest_configure_node (node ):
28- node .slaveinput ['py_test_service' ] = pickle .dumps (node .config .py_test_service )
29-
30-
3117def pytest_sessionstart (session ):
3218 if session .config .getoption ('--collect-only' , default = False ) is True :
3319 return
3420
35- if is_master (session .config ):
36- session .config .py_test_service .init_service (
37- project = session .config .getini ('rp_project' ),
38- endpoint = session .config .getini ('rp_endpoint' ),
39- uuid = session .config .getini ('rp_uuid' ),
40- log_batch_size = int (session .config .getini ('rp_log_batch_size' )),
41- ignore_errors = bool (session .config .getini ('rp_ignore_errors' )),
42- ignored_tags = session .config .getini ('rp_ignore_tags' ),
43- )
21+ PyTestService .init_service (
22+ project = session .config .getini ('rp_project' ),
23+ endpoint = session .config .getini ('rp_endpoint' ),
24+ uuid = session .config .getini ('rp_uuid' ),
25+ log_batch_size = int (session .config .getini ('rp_log_batch_size' )),
26+ ignore_errors = bool (session .config .getini ('rp_ignore_errors' )),
27+ ignored_tags = session .config .getini ('rp_ignore_tags' ),
28+ )
4429
45- session . config . py_test_service .start_launch (
46- session .config .option .rp_launch ,
47- tags = session .config .getini ('rp_launch_tags' ),
48- description = session .config .getini ( ' rp_launch_description' ) ,
49- )
30+ PyTestService .start_launch (
31+ session .config .option .rp_launch ,
32+ tags = session .config .getini ('rp_launch_tags' ),
33+ description = session .config .option . rp_launch_description ,
34+ )
5035
5136
5237def pytest_sessionfinish (session ):
@@ -55,8 +40,7 @@ def pytest_sessionfinish(session):
5540
5641 # FixMe: currently method of RP api takes the string parameter
5742 # so it is hardcoded
58- if is_master (session .config ):
59- session .config .py_test_service .finish_launch (status = 'RP_Launch' )
43+ PyTestService .finish_launch (status = 'RP_Launch' )
6044
6145
6246def pytest_configure (config ):
@@ -65,33 +49,30 @@ def pytest_configure(config):
6549 if not config .option .rp_launch_description :
6650 config .option .rp_launch_description = config .getini ('rp_launch_description' )
6751
68- if is_master (config ):
69- config .py_test_service = PyTestServiceClass ()
70- else :
71- config .py_test_service = pickle .loads (config .slaveinput ['py_test_service' ])
72- config .py_test_service .RP .listener .start ()
52+ if config .pluginmanager .hasplugin ('xdist' ):
53+ raise Exception (
54+ "pytest report portal is not compatible with 'xdist' plugin." )
7355
7456 # set Pytest_Reporter and configure it
7557
7658 if PYTEST_HAS_LOGGING_PLUGIN :
7759 # This check can go away once we support pytest >= 3.3
7860 try :
7961 config ._reporter = RPReportListener (
80- config .py_test_service ,
8162 _pytest .logging .get_actual_log_level (config , 'rp_log_level' )
8263 )
8364 except TypeError :
8465 # No log level set either in INI or CLI
85- config ._reporter = RPReportListener (config . py_test_service )
66+ config ._reporter = RPReportListener ()
8667 else :
87- config ._reporter = RPReportListener (config . py_test_service )
68+ config ._reporter = RPReportListener ()
8869
8970 if hasattr (config , '_reporter' ):
9071 config .pluginmanager .register (config ._reporter )
9172
9273
9374def pytest_unconfigure (config ):
94- config . py_test_service .terminate_service ()
75+ PyTestService .terminate_service ()
9576
9677 if hasattr (config , '_reporter' ):
9778 reporter = config ._reporter
0 commit comments