testcontainers / testcontainers/testcontainers-python
Use SqlServerContainer with pyodbc driver
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 386
- Avg merge
- 4h 40m
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the linked commit diff and the current SqlServerContainer constructor and connection setup. Reproduce the pyodbc examples and trace how the dialect and driver arguments are handled; done means a SqlServerContainer can connect with pyodbc and an explicitly selected ODBC driver.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sql
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100