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

pytest fixture has database refusing connection #30

Open
dtracers opened this issue May 14, 2019 · 2 comments
Open

pytest fixture has database refusing connection #30

dtracers opened this issue May 14, 2019 · 2 comments

Comments

@dtracers
Copy link

I am using python 3.7 and postgresql

@pytest.fixture(autouse=True, scope="session")
def postgres_factory():
    """
    Creates an initial fake database for use in unit tests.
    """
    postgres_factory = postgresql.PostgresqlFactory(cache_initialized_db=True, on_initialized=create_initial_data)
    return postgres_factory


@pytest.fixture(autouse=True, scope="class")
def postgres_instance(postgres_factory):
    fake_db = postgres_factory()
    return fake_db

I have these as pytest fixtures and when it tries to recreate them the first query throws a connection refused error.

@qemtek
Copy link

qemtek commented Oct 15, 2019

Im getting the same problem.. Whenever I try to create a connection to the fake DB when imported as a fixture I get the error

@petroslamb
Copy link

This was perplexing for me too, as this works on and off on slight modifications, without good reason. Although I was using the Postgresql class not the factory, a fellow coworker pointed out to try to pass the port that the error refers to:

psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused

And what solved the problem for me (although it worked at times):

pg = testing.postgresql.Postgresql(
    port=5432,
    postgres_args="-h 127.0.0.1 -F -c logging_collector=off -c max_locks_per_transaction=200",
)

No idea why.

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

3 participants