testcontainers / testcontainers/testcontainers-python

Use SqlServerContainer with pyodbc driver

未关闭
#244 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

✅ close on merge 📦 package: mssql
主要语言
Python
星标
2.3k
派生
386
平均合并
4 小时 40 分钟
30 天内合并 PR
1

描述

In https://github.com/testcontainers/testcontainers-python/commit/fc5f2df4ba8157d21ecbf3a9a90cd45a61049f90#diff-313a71bf8d0b95ccd84a98f198294e10a7c7086c527efb513d9c6619a12086ee the default driver of SqlServerContainer was changed to pymssql.
Currently, I use the pyodbc driver to communicate with MSSQL databases. This is not possible anymore since then. I've tried

test_container = SqlServerContainer(
        image="mcr.microsoft.com/mssql/server:2017-latest",
        dialect="mssql+pyodbc",
    )

which leads to a timeout
testcontainers.core.exceptions.TimeoutException: Wait time (120s) exceeded for _connect(args: (), kwargs {}). Exception: (pyodbc.InterfaceError) ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Alternatively, I've tried to specify the driver

test_container = SqlServerContainer(
        image="mcr.microsoft.com/mssql/server:2017-latest",
        dialect="mssql+pyodbc",
        driver = "ODBC Driver 17 for SQL Server"
    )

but this keyword isn't allowed anymore.
> raise create_unexpected_kwargs_error('run', kwargs) E TypeError: run() got an unexpected keyword argument 'driver'

Is it still the goal of testcontainers to support using the pyodbc driver? If so, I might be motivated to support a little bit making this possible again in 3.6.x versions.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先查看链接的提交 diff,以及当前的 SqlServerContainer 构造函数和连接设置。重现 pyodbc 示例,并跟踪 dialect 和 driver 参数是如何处理的;当 SqlServerContainer 能够使用 pyodbc 和显式选择的 ODBC 驱动程序建立连接时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python, sql
领域
databases
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。