@@ -34,20 +34,25 @@ def pytest_collection_modifyitems(config, items):
3434 if "slow" in item .keywords :
3535 item .add_marker (skip_slow )
3636
37+ def source_uri (request : pytest .FixtureRequest ):
38+ """Provide the source MongoDB URI."""
39+ return request .config .getoption ("--source-uri" ) or os .environ ["TEST_SOURCE_URI" ]
40+
41+ def target_uri (request : pytest .FixtureRequest ):
42+ """Provide the target MongoDB URI."""
43+ return request .config .getoption ("--target-uri" ) or os .environ ["TEST_TARGET_URI" ]
3744
3845@pytest .fixture (scope = "session" )
3946def source_conn (request : pytest .FixtureRequest ):
4047 """Provide a MongoClient connection to the source MongoDB."""
41- uri = request .config .getoption ("--source-uri" ) or os .environ ["TEST_SOURCE_URI" ]
42- with MongoClient (uri ) as conn :
48+ with MongoClient (source_uri (request )) as conn :
4349 yield conn
4450
4551
4652@pytest .fixture (scope = "session" )
4753def target_conn (request : pytest .FixtureRequest ):
4854 """Provide a MongoClient connection to the target MongoDB."""
49- uri = request .config .getoption ("--target-uri" ) or os .environ ["TEST_TARGET_URI" ]
50- with MongoClient (uri ) as conn :
55+ with MongoClient (target_uri (request )) as conn :
5156 yield conn
5257
5358
@@ -76,11 +81,13 @@ def drop_all_database(source_conn: MongoClient, target_conn: MongoClient):
7681 testing .drop_all_database (target_conn )
7782
7883
79- PML_PROC : subprocess .Popen = None
84+ PLM_PROC : subprocess .Popen = None
8085
8186
82- def start_plm (plm_bin : str ):
83- rv = subprocess .Popen ([plm_bin , "--reset-state" , "--log-level=trace" ])
87+ def start_plm (plm_bin : str , request : pytest .FixtureRequest ):
88+ source = source_uri (request )
89+ target = target_uri (request )
90+ rv = subprocess .Popen ([plm_bin ,"--source" , source ,"--target" , target , "--reset-state" , "--log-level=trace" ])
8491 time .sleep (1 )
8592 return rv
8693
@@ -97,15 +104,15 @@ def manage_plm_process(request: pytest.FixtureRequest, plm_bin: str):
97104 yield
98105 return
99106
100- global PML_PROC # pylint: disable=W0603
101- PML_PROC = start_plm (plm_bin )
107+ global PLM_PROC # pylint: disable=W0603
108+ PLM_PROC = start_plm (plm_bin , request )
102109
103110 def teardown ():
104- if PML_PROC and PML_PROC .poll () is None :
105- stop_plm (PML_PROC )
111+ if PLM_PROC and PLM_PROC .poll () is None :
112+ stop_plm (PLM_PROC )
106113
107114 request .addfinalizer (teardown )
108- yield PML_PROC
115+ yield PLM_PROC
109116
110117
111118@pytest .hookimpl (hookwrapper = True )
@@ -122,7 +129,7 @@ def restart_plm_on_failure(request: pytest.FixtureRequest, plm_bin: str):
122129
123130 if hasattr (request .node , "rep_call" ) and request .node .rep_call .failed :
124131 # the test failed. restart plm process with a new state
125- global PML_PROC # pylint: disable=W0603
126- if PML_PROC and plm_bin :
127- stop_plm (PML_PROC )
128- PML_PROC = start_plm (plm_bin )
132+ global PLM_PROC # pylint: disable=W0603
133+ if PLM_PROC and plm_bin :
134+ stop_plm (PLM_PROC )
135+ PLM_PROC = start_plm (plm_bin , request )
0 commit comments