-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests fail in container #90
Comments
I just copied your Dockerfile (with some adjustments, as we dont have a requirements.txt, etc) and ran this repo's tests inside a container (locally) and it appears to have all ran fine. I could definitely imagine our use of I'd be interested to know:
|
Interesting. What command are you running in terminal? Maybe I'm mixing up commands. The goal is to set it up on GitLab using dind, Also, planning to do a PR for the CI section of the documentation once I have a working setup. |
For running pytest-mock-resources's own tests:
If that works for you, then it kind of makes me think it's related to gevent (given that it was oddly in your stacktrace?)? |
Hmm. I still can't get it to work. Here's a minimal example:
tests/conftest.py
tests/test_example.py
Dockerfile
requirements.txt
The error I'm getting is: E sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
E Is the server running on host "localhost" (127.0.0.1) and accepting
E TCP/IP connections on port 5532?
E could not connect to server: Cannot assign requested address
E Is the server running on host "localhost" (::1) and accepting
E TCP/IP connections on port 5532?
E
E (Background on this error at: http://sqlalche.me/e/e3q8)
/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:127: OperationalError
... # More errors
def check_postgres_fn():
try:
get_sqlalchemy_engine(config["root_database"])
except sqlalchemy.exc.OperationalError:
raise ContainerCheckFailed(
"Unable to connect to a presumed Postgres test container via given config: {}".format(
> config
)
)
E pytest_mock_resources.container.ContainerCheckFailed: Unable to connect to a presumed Postgres test container via given config: {'username': 'user', 'password': 'password', 'port': 5532, 'root_database': 'dev', 'image': 'postgres:9.6.10-alpine'}
/usr/local/lib/python3.6/site-packages/pytest_mock_resources/container/postgres.py:56: ContainerCheckFailed |
I did have to change your conftest to from pytest_mock_resources import create_postgres_fixture
from example import Base
pg = create_postgres_fixture(Base, scope="module", session=True) (which make perfect sense), but otherwise this passes for me 😕. you definitely don't have a zombie container running on that port, or otherwise have something bound to that port on the host? |
I've made the changes. But it's still not working. What platform are you using? I'm using linux. |
I'm currently on osx, but i've run it on linux and our CI (circle CI) runs (in docker) on linux as well. The changes I made would only apply after you've successfully instantiated the fixture (i.e. in the test body), whereas you're failing to start up the container before the tests start. It's still not clear to me whether you're seeing the container spin up at all (and then be torn down). I.e. your error is caused by it not being able to connect for some reason, vs there being a service which we're trying to connect to with incorrect credentials. In addition to clarity on the above, i'd be interested in seeing if you could run |
It runs successfully, here's output:
One thing I've noticed is that I can't access any service on |
We have an environment variable which can be used to configure the host that it looks at It does feel odd to me that we wouldn't have this problem in our other linux environments though. |
Hmm. Let me look into it. I'm considering running a |
the only linux machines i can confidently use as comparisons are CI (circleci), which would be Ubuntu, afaik |
Hey @michaelbukachi This problem makes sense - docker in *nix systems does not seem to support Following this issue: docker/for-linux#264 (comment) Could you do the following and get back to us? -
If this works then it confirms the issue and means we could add something to that "get_docker_host" function to do the above automatcially. You could also run your docker container with the |
Passing |
Got it working using
Next up, testing on gitlab!:smile: |
Here's a working gitlab configuration:
Do I need to do a PR for the documentation?:smiley: |
hah, fantastic, yes please 👍 |
Given the now merged doc update on working in dind/gitlab, closing this issue. Feel free to suggest I reopen if that's not true |
Describe the bug
I'm trying to run tests within a container but they keep failing
Environment
To Reproduce
Steps to reproduce the behavior:
docker run -v /var/run/docker.sock:/var/run/docker.sock image
Here's the Dockerfile
Expected behavior
Tests to run successfully.
Actual Behavior
Additional context
When I run tests outside the container they run successfully.
The text was updated successfully, but these errors were encountered: