Skip to content
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

Live database support #13

Open
UriCW opened this issue Jan 3, 2020 · 3 comments
Open

Live database support #13

UriCW opened this issue Jan 3, 2020 · 3 comments

Comments

@UriCW
Copy link

UriCW commented Jan 3, 2020

To the best of my understanding, this "magically" uses the Postgresql executable to create a separate database. This works great for testing on my machine, but when I want to run these test on my CI environment (using gitlab's ci/cd toolchain) I run into a problem.

I either need to install postgresql on the docker image the tests run on or use a pre installed postgresql image. further when I try these approaches I run into other problems, for example it doesn't like that the tests are running as root.

Ideally, I could still have a way to use a live database, which you can setup and demolish using "services": postgres:latest in the .gitlab-ci.yml file as part of the normal CI pipeline.

For the time being, I will probably add a fixture to conftest.py that checks some environment variables and either returns a real postgresql db context or a pytest-psql postgresql_db context depending on the environment.

Would be cool if i could just set some options to pass a real database connection details instead.

Apologies if this is already possible I couldn't find out how.

@ash211
Copy link

ash211 commented Jan 6, 2020

I was very interested in this also. I think I have it working with this conftest.py setting:

import pytest
import os

if "TEST_POSTGRESQL_URI" in os.environ:
    @pytest.fixture(scope='session')
    def database_uri():
        return os.getenv("TEST_POSTGRESQL_URI")

Setting that environment variable to postgresql://[email protected]:5432/test seems to use the existing database as expected, vs creating a new one.

Does this work for you too?

@jannismain
Copy link

@ash211 Thank you very much for your comment :-) This helped me move forward using an existing database for testing, while I'm waiting on input on #20

@nayyarv
Copy link

nayyarv commented Sep 4, 2020

@ash211 I can also can say this worked well for me and is worth official support as a PR.

Within gitlab's services infra: https://docs.gitlab.com/ee/ci/services/postgres.html, I found setting the hostname to postgres like to postgresql://postgres@postgres:5432/testwas also good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants