嗨,我正在尝试用postgresql数据库做一个unittest,它使用sqlalchemy和alembic
我还在docker postgresql上运行它
我在跟踪测试.postgresql(docs)要设置临时postgresql实例,请处理数据库测试并编写以下测试:
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')
craw_bds_obj()基本上保存URL中的信息,并使用会话.提交()并返回类型数据
当我尝试运行测试时,它返回以下错误:
^{pr2}$文件上说测试.postgresql.postgresql实例化时执行initdb和postgres。删除Postgresql对象时,它终止Postgresql实例并删除临时目录。“
为什么我已经安装了initdb错误测试.postgresql让postgresql在我的docker上运行?在
编辑:
我也设置了我的数据路径,但它仍然返回相同的错误
dockerfile文件:
FROM python:slim-jessie
ADD requirements.txt /app/requirements.txt
ADD . /app/
WORKDIR /app/
RUN pip install -r requirements.txt
docker编写:
postgres:
image: postgres
restart: always
environment:
- 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/data
pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
volumes:
- ./data/pgadmin:/root/.pgadmin
ports:
- "${PGADMIN_PORT}:80"
logging:
driver: none
restart: unless-stopped
worker:
build:
context: .
dockerfile: Dockerfile
command: "watchmedo auto-restart --recursive -p '*.py'"
environment:
- C_FORCE_ROOT=1
volumes:
- .:/app
links:
- rabbit
depends_on:
- rabbit
- postgres
testing.postgresql.Postgresql(copy_data_from='data/postgres:/var/lib/postgresql/data')
您需要以
postgresql
用户而不是root
的身份运行此命令,因此您可以尝试使用以下方式运行命令:或者
^{pr2}$或者将
USER postgres
添加到您的Dockerfile
并检查要求:
更新
要使
copy_data_from
正常工作,您应该首先生成文件夹:然后加上这个:
相关问题 更多 >
编程相关推荐