-
Notifications
You must be signed in to change notification settings - Fork 51
Description
What action do you want to perform
I'm trying to run some postgres tests in a docker CI github action, and I am keeping "no password sent" error. It seems fairly similar to this issue, #294, but I'm using the latest package version, 4.1, and I think that bug is fixed.
What is the correct syntax to get the docker db to accept the password? This use to work on Travis with pytest-postgresql==2.3 but I'm trying to migrate to Github Actions and update to the latest code.
When I set a debug point in the action and ssh into the container, I can manually run the DatabaseJanitor code and it works. So maybe it's this specific use of it?
What are the results
psycopg.OperationalError: connection failed: fe_sendauth: no password supplied. Full traceback is at the bottom.
Here is my Github Action service setup:
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:14
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: test
POSTGRES_PORT: 5432
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
and here is my pytest fixture.
@pytest.fixture(scope='module')
def database(request, postgresql_noproc):
''' Module fixture to initialize a real database or a test postgresql database '''
if hasattr(request, 'param'):
# yield a real database
yield request.param
else:
# check if request is coming from a sqla db or peewee db
issqla = 'sqladbs' in request.module.__name__ or 'sqlalchemy' in request.module.__name__
# initialize the test database
# uses https://github.com/ClearcodeHQ/pytest-postgresql
janitor = DatabaseJanitor('postgres', 'localhost', 5432, 'test', '14', password="test")
janitor.init()
db = sqla_prepdb() if issqla else pw_prepdb()
yield db
db = None
janitor.drop()
I've also tried using DatabaseJanitor as a context manager, and I've tried using postgresql_noproc to set the config parameters
janitor = DatabaseJanitor(postgresql_noproc.user, postgresql_noproc.host,
postgresql_noproc.port, 'test', postgresql_noproc.version, password="test")
What are the expected results
My tests run locally successfully. It only fails when run on CI.
Traceback
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/psycopg/connection.py:572: OperationalError
_______________ ERROR at setup of TestFactory.test_a_transaction _______________
request = <SubRequest 'postgresql_noproc' for <Function test_db_connected>>
@pytest.fixture(scope="session")
def postgresql_noproc_fixture(request: FixtureRequest) -> Iterator[NoopExecutor]:
"""
Noop Process fixture for PostgreSQL.
:param request: fixture request object
:returns: tcp executor-like object
"""
config = get_config(request)
pg_host = host or config["host"]
pg_port = port or config["port"] or 5432
pg_user = user or config["user"]
pg_password = password or config["password"]
pg_dbname = xdistify_dbname(dbname or config["dbname"])
pg_options = options or config["options"]
pg_load = load or config["load"]
noop_exec = NoopExecutor(
host=pg_host,
port=pg_port,
user=pg_user,
***
dbname=pg_dbname,
options=pg_options,
)
template_dbname = f"{noop_exec.dbname}_tmpl"
with DatabaseJanitor(
user=noop_exec.user,
host=noop_exec.host,
port=noop_exec.port,
dbname=template_dbname,
> version=noop_exec.version,
***
) as janitor:
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_postgresql/factories/noprocess.py:91:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_postgresql/executor_noop.py:75: in version
options=self.options,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'psycopg.Connection'>
conninfo = "dbname=postgres user=postgres host=127.0.0.1 port=5432 password='' options=''"
autocommit = False, row_factory = None, context = None
kwargs = {'dbname': 'postgres', 'host': '127.0.0.1', 'options': '', 'password': '', ...}
params = {'connect_timeout': None, 'dbname': 'postgres', 'host': '127.0.0.1', 'options': '', ...}
@classmethod # type: ignore[misc] # https://github.com/python/mypy/issues/11004
def connect(
cls,
conninfo: str = "",
*,
autocommit: bool = False,
row_factory: Optional[RowFactory[Row]] = None,
context: Optional[AdaptContext] = None,
**kwargs: Any,
) -> "Connection[Any]":
"""
Connect to a database server and return a new `Connection` instance.
"""
params = cls._get_connection_params(conninfo, **kwargs)
conninfo = make_conninfo(**params)
try:
rv = cls._wait_conn(
cls._connect_gen(conninfo, autocommit=autocommit),
timeout=params["connect_timeout"],
)
except e.Error as ex:
> raise ex.with_traceback(None)
E psycopg.OperationalError: connection failed: fe_sendauth: no password supplied