Hi i'm trying to make a unittest with postgresql database that use sqlalchemy and alembic
Also im running it on docker postgresql
I'm following the docs of testing.postgresql(docs) to set up a temporary postgresql instance handle database testing and wrote the the following test:
def test_crawl_bds_obj(self):with testing.postgresql.Postgresql() as postgresql:engine.create_engine(postgresql.url())result = crawl_bds_obj(1 ,'/ban-can-ho-chung-cu-duong-mai-chi-tho-phuong-an-phu-prj-the-sun-avenue/nh-chu-gap-mat-tien-t-q2-thuoc-du-tphcm-pr22171626')self.assertEqual(result, 'sell')
The crawl_bds_obj() basically save information from an URL and save it to the database using session.commit() and return the type data
When i tried to run the test it return the following error:
ERROR: test_crawl_bds_obj (tests.test_utils.TestUtils)
raise RuntimeError("command not found: %s" % name)
RuntimeError: command not found: initdb
In the docs it said that "testing.postgresql.Postgresql executes initdb and postgres on instantiation. On deleting Postgresql object, it terminates PostgreSQL instance and removes temporary directory."
So why am i getting initdb error when i already installed testing.postgresql and had postgresql running on my docker?
EDIT:
I aslo had set my data path but it still return the same error
dockerfile:
FROM python:slim-jessie
ADD requirements.txt /app/requirements.txt
ADD . /app/
WORKDIR /app/
RUN pip install -r requirements.txt
docker-compose:
postgres:image: postgresrestart: alwaysenvironment:- POSTGRES_USER=${POSTGRES_DEFAULT_USER}- POSTGRES_PASSWORD=${POSTGRES_DEFAULT_PASSWORD}- POSTGRES_DB=${POSTGRES_DEFAULT_DB}- POSTGRES_PORT=${POSTGRES_DEFAULT_PORT}volumes:- ./data/postgres:/var/lib/postgresql/datapgadmin:image: dpage/pgadmin4environment:PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}volumes:- ./data/pgadmin:/root/.pgadminports:- "${PGADMIN_PORT}:80"logging:driver: nonerestart: unless-stoppedworker:build:context: .dockerfile: Dockerfilecommand: "watchmedo auto-restart --recursive -p '*.py'"environment:- C_FORCE_ROOT=1volumes:- .:/applinks:- rabbitdepends_on:- rabbit- postgres
testing.postgresql.Postgresql(copy_data_from='data/postgres:/var/lib/postgresql/data')