@@ -27,6 +27,41 @@ def pytest_generate_tests(metafunc):
2727 loop_type = ['asyncio' , 'uvloop' ] if uvloop else ['asyncio' ]
2828 metafunc .parametrize ("loop_type" , loop_type )
2929
30+ if "mysql_address" in metafunc .fixturenames :
31+ mysql_addresses = []
32+ ids = []
33+
34+ opt_mysql_address = list (metafunc .config .getoption ("mysql_address" ))
35+ for i in range (len (opt_mysql_address )):
36+ if "=" in opt_mysql_address [i ]:
37+ label , addr = opt_mysql_address [i ].split ("=" , 1 )
38+ ids .append (label )
39+ else :
40+ addr = opt_mysql_address [i ]
41+ ids .append ("tcp{}" .format (i ))
42+
43+ if ":" in addr :
44+ addr = addr .split (":" , 1 )
45+ mysql_addresses .append ((addr [0 ], int (addr [1 ])))
46+ else :
47+ mysql_addresses .append ((addr , 3306 ))
48+
49+ # default to connecting to localhost
50+ if len (mysql_addresses ) == 0 :
51+ mysql_addresses = [("127.0.0.1" , 3306 )]
52+ ids = ["tcp-local" ]
53+
54+ assert len (mysql_addresses ) == len (set (mysql_addresses )), \
55+ "mysql targets are not unique"
56+ assert len (ids ) == len (set (ids )), \
57+ "mysql target names are not unique"
58+
59+ metafunc .parametrize ("mysql_address" ,
60+ mysql_addresses ,
61+ ids = ids ,
62+ scope = "session" ,
63+ )
64+
3065
3166# This is here unless someone fixes the generate_tests bit
3267@pytest .fixture (scope = 'session' )
@@ -101,6 +136,15 @@ def pytest_configure(config):
101136 )
102137
103138
139+ def pytest_addoption (parser ):
140+ parser .addoption (
141+ "--mysql-address" ,
142+ action = "append" ,
143+ default = [],
144+ help = "list of addresses to connect to: [name=]host[:port]" ,
145+ )
146+
147+
104148@pytest .fixture
105149def mysql_params (mysql_server ):
106150 params = {** mysql_server ['conn_params' ],
@@ -205,7 +249,7 @@ def ensure_mysql_version(request, mysql_image, mysql_tag):
205249
206250
207251@pytest .fixture (scope = 'session' )
208- def mysql_server (mysql_image , mysql_tag ):
252+ def mysql_server (mysql_image , mysql_tag , mysql_address ):
209253 ssl_directory = os .path .join (os .path .dirname (__file__ ),
210254 'ssl_resources' , 'ssl' )
211255 ca_file = os .path .join (ssl_directory , 'ca.pem' )
@@ -216,8 +260,8 @@ def mysql_server(mysql_image, mysql_tag):
216260 # ctx.verify_mode = ssl.CERT_NONE
217261
218262 server_params = {
219- 'host' : '127.0.0.1' ,
220- 'port' : 3306 ,
263+ 'host' : mysql_address [ 0 ] ,
264+ 'port' : mysql_address [ 1 ] ,
221265 'user' : 'root' ,
222266 'password' : os .environ .get ("MYSQL_ROOT_PASSWORD" ),
223267 'ssl' : ctx ,
0 commit comments