1313def test_docker_run_mysql ():
1414 config = MySqlContainer ("mysql:8.3.0" )
1515 with config as mysql :
16- engine = sqlalchemy .create_engine (mysql .get_connection_url ())
16+ connection_url = mysql .get_connection_url ()
17+
18+ assert mysql .dialect is None
19+ assert connection_url .startswith ("mysql://" )
20+
21+ engine = sqlalchemy .create_engine (connection_url )
1722 with engine .begin () as connection :
1823 result = connection .execute (sqlalchemy .text ("select version()" ))
1924 for row in result :
@@ -55,7 +60,7 @@ def test_docker_run_mariadb(version: str):
5560
5661def test_docker_env_variables ():
5762 with (
58- mock .patch .dict ("os.environ" , MYSQL_USER = "demo" , MYSQL_DATABASE = "custom_db" ),
63+ mock .patch .dict ("os.environ" , MYSQL_DIALECT = "pymysql" , MYSQL_USER = "demo" , MYSQL_DATABASE = "custom_db" ),
5964 MySqlContainer ("mariadb:10.6.5" ).with_bind_ports (3306 , 32785 ) as container ,
6065 ):
6166 url = container .get_connection_url ()
@@ -75,18 +80,18 @@ def test_quoted_password():
7580 user = "root"
7681 password = "p@$%25+0&%rd :/!=?"
7782 quoted_password = "p%40%24%2525+0%26%25rd %3A%2F%21%3D%3F"
78- driver = "pymysql"
79- with MySqlContainer ("mariadb:10.6.5" , username = user , password = password ) as container :
83+ dialect = "pymysql"
84+ with MySqlContainer ("mariadb:10.6.5" , dialect = dialect , username = user , password = password ) as container :
8085 host = container .get_container_host_ip ()
8186 port = container .get_exposed_port (3306 )
82- expected_url = f"mysql+{ driver } ://{ user } :{ quoted_password } @{ host } :{ port } /test"
87+ expected_url = f"mysql+{ dialect } ://{ user } :{ quoted_password } @{ host } :{ port } /test"
8388 url = container .get_connection_url ()
8489 assert url == expected_url
8590
8691 with sqlalchemy .create_engine (expected_url ).begin () as connection :
8792 connection .execute (sqlalchemy .text ("select version()" ))
8893
89- raw_pass_url = f"mysql+{ driver } ://{ user } :{ password } @{ host } :{ port } /test"
94+ raw_pass_url = f"mysql+{ dialect } ://{ user } :{ password } @{ host } :{ port } /test"
9095 with pytest .raises (Exception ):
9196 with sqlalchemy .create_engine (raw_pass_url ).begin () as connection :
9297 connection .execute (sqlalchemy .text ("select version()" ))
0 commit comments