testcontainers / testcontainers-python

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.
https://testcontainers-python.readthedocs.io/en/latest/
Apache License 2.0
1.54k stars 281 forks source link

Bug: localnpipe translation not working in v3 #600

Closed fraser-langton closed 3 months ago

fraser-langton commented 4 months ago

Describe the bug

Cannot do the most basic use case

To Reproduce

I copied the example from the docs word for word

from testcontainers.postgres import PostgresContainer
import sqlalchemy

with PostgresContainer("postgres:16") as postgres:  # hangs here
    engine = sqlalchemy.create_engine(postgres.get_connection_url())
    with engine.begin() as connection:
        result = connection.execute(sqlalchemy.text("select version()"))
        version, = result.fetchone()
version

Runtime environment

Windows 11 + Python 3.8.10

systeminfo

Host Name:                 HARD-147
OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22631 N/A Build 22631
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Organization:   N/A
System Manufacturer:       Dell Inc.
System Model:              XPS 9320
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 154 Stepping 3 GenuineIntel ~2100 Mhz
BIOS Version:              Dell Inc. 2.11.0, Wed 6/03 Mar
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

docker info

 Client:
 Version:    24.0.6
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2-desktop.5
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.23.0-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.9
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scan.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.0.9
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 14
 Server Version: 24.0.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8165feabfdfe38c65b599c4993d227328c231fca
 runc version: v1.1.8-0-g82f18fe
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.90.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 15.43GiB
 Name: HARD-147
 ID: 759eaec7-31b5-4467-a6c8-1920aba7cd2a
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

freeze

aiobotocore==2.7.0
aiohttp==3.8.6
aioitertools==0.11.0
aiosignal==1.3.1
alabaster==0.7.13
alembic==1.11.3
anyio==3.7.1
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
astroid==2.15.6
asttokens==2.4.1
astunparse==1.6.3
async-lru==2.0.4
async-timeout==4.0.3
atomicwrites==1.4.1
attrs==23.1.0
autohooks==23.7.0
autohooks-plugin-black==23.7.0
aws-cdk-lib==2.110.1
aws-cdk.asset-awscli-v1==2.2.201
aws-cdk.asset-kubectl-v20==2.1.2
aws-cdk.asset-node-proxy-agent-v6==2.0.1
Babel==2.12.1
backcall==0.2.0
backports.zoneinfo==0.2.1
beautifulsoup4==4.12.2
black==23.7.0
bleach==6.0.0
blosc2==2.0.0
bokeh==3.1.1
boto==2.49.0
boto3==1.28.85
botocore==1.31.85
branca==0.6.0
bs4==0.0.1
build==0.10.0
bytecode==0.15.1
cattrs==23.2.3
certifi==2023.11.17
cffi==1.15.1
charset-normalizer==3.3.2
click==8.0.4
click-plugins==1.1.1
cligj==0.7.2
cloudpickle==2.2.1
colorama==0.4.6
colorful==0.5.5
comm==0.1.3
configparser==3.8.1
confluent-kafka==2.2.0
constructs==10.3.0
contextlib2==21.6.0
contourpy==1.0.7
coverage==7.3.2
cryptography==41.0.7
cycler==0.11.0
Cython==3.0.9
dask==2023.5.0
databricks-connect==13.0.1
databricks-sdk==0.5.0
ddsketch==2.0.4
ddtrace==1.7.5
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
Deprecated==1.2.13
deprecation==2.1.0
dill==0.3.7
diskcache==5.6.3
docker==7.1.0
docopt==0.6.2
docstring_parser==0.16
docutils==0.20.1
entrypoints==0.4
envier==0.5.0
et-xmlfile==1.1.0
exceptiongroup==1.2.0
executing==2.0.1
fastapi==0.79.1
fastapi-pagination==0.12.5
fastjsonschema==2.17.1
fiona==1.9.5
folium==0.14.0
fonttools==4.39.4
fqdn==1.5.1
freezegun==1.2.2
frozenlist==1.4.1
fsspec==2023.12.2
future==0.18.3
GeoAlchemy2==0.13.3
geographiclib==2.0
geojson==2.5.0
geopandas==0.13.2
geopy==2.4.1
ghp-import==2.1.0
gitdb==4.0.11
GitPython==3.1.40
gmplot==1.4.1
googleapis-common-protos==1.60.0
googlemaps==2.5.1
gpd==1.1.1
greenlet==3.0.3
grpcio==1.57.0
grpcio-status==1.57.0
h11==0.14.0
h2==4.1.0
hpack==4.0.0
httpcore==0.16.3
httpx==0.23.3
hyperframe==6.0.1
idna==3.6
imagesize==1.4.1
importlib-metadata==7.0.0
importlib-resources==6.1.1
iniconfig==2.0.0
ipdb==0.13.13
ipykernel==6.23.1
ipython==8.12.3
ipython-genutils==0.2.0
ipywidgets==8.0.6
iso8601==0.1.11
isoduration==20.11.0
isort==5.12.0
itsdangerous==2.1.2
jedi==0.19.1
Jinja2==3.1.2
jmespath==1.0.1
jsii==1.92.0
json5==0.9.24
jsonpointer==2.3
jsonschema==3.2.0
jsonschema-specifications==2023.11.2
jsonseq==1.0.0
jupyter-console==6.6.3
jupyter-events==0.10.0
jupyter-lsp==2.2.4
jupyter_client==7.4.9
jupyter_core==5.7.2
jupyter_server==2.13.0
jupyter_server_terminals==0.4.4
jupyterlab==4.1.5
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.7
jupyterlab_server==2.25.4
kiwisolver==1.4.4
lazy-object-proxy==1.9.0
locket==1.0.0
loguru==0.6.0
Mako==1.3.0
mangum==0.17.0
mapbox-tilesets==1.9.3
mapbox-vector-tile==1.2.1
Markdown==3.6
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib==3.7.1
matplotlib-inline==0.1.6
mccabe==0.7.0
mdurl==0.1.2
mercantile==1.1.6
mergedeep==1.3.4
mistune==2.0.5
mkdocs==1.6.0
mkdocs-autorefs==1.0.1
mkdocs-get-deps==0.2.0
mkdocstrings==0.25.1
moto==4.2.12
msgpack==1.0.8
multidict==6.0.4
multimethod==1.10
mypy==1.8.0
mypy-extensions==1.0.0
nbclassic==1.0.0
nbclient==0.8.0
nbconvert==7.4.0
nbformat==5.8.0
nest-asyncio==1.5.6
networkx==3.1
notebook==6.5.6
notebook_shim==0.2.3
numexpr==2.8.6
numpy==1.24.4
openpyxl==3.1.2
opentelemetry-api==1.16.0
outcome==1.3.0.post0
overrides==7.3.1
packaging==23.2
pandandic==0.2.2
pandas==1.5.3
pandera==0.17.2
pandocfilters==1.5.0
parso==0.8.3
partd==1.4.0
pathspec==0.12.1
pdoc3==0.10.0
pickleshare==0.7.5
piexif==1.1.3
Pillow==9.5.0
pipreqs==0.4.13
pkgutil_resolve_name==1.3.10
platformdirs==4.1.0
pluggy==1.3.0
ply==3.11
pontos==23.3.5
prometheus-client==0.17.0
prompt-toolkit==3.0.43
protobuf==3.20.3
psutil==5.9.5
psycopg==3.1.19
psycopg2-binary==2.9.9
ptyprocess==0.7.0
publication==0.0.3
pure-eval==0.2.2
py==1.11.0
py-cpuinfo==9.0.0
py-mini-racer==0.6.0
py4j==0.10.9.7
pyarrow==15.0.1
pyclipper==1.3.0.post5
pycparser==2.21
pydantic==1.10.13
pydocstyle==6.3.0
pydot==1.4.2
Pygments==2.17.2
pylint==2.17.5
pymbtiles==0.5.0
pymdown-extensions==10.8.1
pyparsing==3.0.9
pyproj==3.5.0
pyproject_hooks==1.0.0
pyrsistent==0.20.0
PySocks==1.7.1
pytest==7.0.1
pytest-asyncio==0.23.6
pytest-cov==2.12.1
pytest-html==3.1.1
pytest-metadata==3.0.0
pytest-mock==3.12.0
pytest-schema==0.1.1
python-dateutil==2.8.2
python-dotenv==1.0.0
python-http-client==3.3.7
python-json-logger==2.0.7
python-multipart==0.0.6
pytz==2023.3.post1
pywin32==306
pywinpty==2.0.10
PyYAML==6.0.1
pyyaml_env_tag==0.1
pyzmq==24.0.1
qtconsole==5.4.3
QtPy==2.3.1
referencing==0.32.0
requests==2.31.0
requests-toolbelt==1.0.0
responses==0.24.1
result==0.17.0
returns==0.22.0
rfc3339-validator==0.1.4
rfc3986==1.5.0
rfc3986-validator==0.1.1
rich==13.7.0
rpds-py==0.15.2
s3fs==0.4.2
s3transfer==0.7.0
schema==0.7.5
scipy==1.10.1
selenium==4.15.2
semver==2.13.0
Send2Trash==1.8.2
sendgrid==6.10.0
shapely==2.0.4
simplekml==1.3.6
six==1.16.0
smmap==5.0.1
sniffio==1.3.0
snowballstemmer==2.2.0
sortedcontainers==2.4.0
soupsieve==2.4.1
Sphinx==7.1.2
sphinxcontrib-applehelp==1.0.4
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
sqlakeyset==2.0.1687912386
SQLAlchemy==1.4.50
SQLAlchemy-Utils==0.41.1
stack-data==0.6.3
starkbank-ecdsa==2.2.0
starlette==0.19.1
structlog==22.3.0
swifter==1.4.0
tables==3.8.0
tabulate==0.8.10
tafra==1.0.10
tenacity==8.2.3
terminado==0.17.1
testcontainers==3.7.1
tinycss2==1.2.1
toml==0.10.2
tomli==2.0.1
tomlkit==0.12.3
toolz==0.12.0
tornado==6.3.2
tqdm==4.66.1
traitlets==5.14.0
trio==0.23.1
trio-websocket==0.11.1
typeguard==2.13.3
typing-inspect==0.9.0
typing_extensions==4.9.0
tzdata==2023.3
uri-template==1.2.0
urllib3==1.26.18
uvicorn==0.25.0
watchdog==4.0.1
wcwidth==0.2.12
webcolors==1.13
webencodings==0.5.1
websocket-client==1.5.2
Werkzeug==3.0.1
widgetsnbextension==4.0.7
win32-setctime==1.1.0
wrapt==1.15.0
wsproto==1.2.0
xmltodict==0.13.0
xyzservices==2023.7.0
yamlmagic==0.2.0
yarg==0.1.9
yarl==1.9.4
zipp==3.17.0
fraser-langton commented 4 months ago

Found a fix, just os.environ["TC_HOST"] = "localhost"

It took me longer than it should've to find the fix because all I could see was Waiting to be ready... - it doesn't show the exception until max retries is done and with that at 120 as a default I never waited the full amount because I had no indication of how many tries it was doing. And also maybe should log the errors each time it happens?

Where I found the fix https://github.com/testcontainers/testcontainers-python/issues/108#issuecomment-1540584987

fraser-langton commented 4 months ago

And also maybe should log the errors each time it happens?

Hang on... in waiting_utils.py it does log, but setup_logger enforces logging config, as a package this should not be happening? Logging config should be up to application not the package

alexanderankin commented 3 months ago

I'm slightly confused about why the TC_HOST fix was necessary despite the fix in #427

fraser-langton commented 3 months ago

@alexanderankin version? I had 3.7.1

alexanderankin commented 3 months ago

The v3 line is from 2022/jan 2023, the first release of v4 was this year with all new maintainers of the project

alexanderankin commented 3 months ago

@fraser-langton if you run into difficulties with an up-to-date version, please open a new issue.

fraser-langton commented 3 months ago

@alexanderankin what about changing the usage of setup_logger which made this issue harder to debug, worthwhile fixing? Make a different issue?

alexanderankin commented 3 months ago

would you consider that breaking? or any ideas about how to soften the breaking of that change (config flag :((( ?) - I put it on my v5 list #631