问题描述
由于无法确定如何调试以下问题,我已经挠头了几个小时。
上下文
我在一个项目上使用pytest和pytest-postgresql来学习TDD。
pytest-postgres使我能够使用在套接字的/ tmp目录中实现postgresql数据库的装置。
这曾经很好用,并在以下内容中进行了解释:
- 文档https://pypi.org/project/pytest-postgresql/
- 本文: https://medium.com/@geoffreykoh/fun-with-fixtures-for-database-applications-8253eaf1a6d。
问题
使用该夹具的样本测试会产生以下错误:
> raise CalledProcessError(retcode,process.args,output=stdout,stderr=stderr)
E subprocess.CalledProcessError: Command '['/usr/bin/pg_ctl','initdb','--pgdata','/tmp/postgresqldata.12836','-o','--username=postgres --auth=trust']' returned non-zero exit status 1.
/usr/lib/python3.8/subprocess.py:512: CalledProcessError
/usr/lib/python3.8/subprocess.py:512: CalledProcessError
---------------------------- Captured stderr setup -----------------------------
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
initdb: error: invalid locale settings; check LANG and LC_* environment variables
pg_ctl: database system initialization Failed
=========================== short test summary info ============================
ERROR tests/adapters/test_orm.py::test_sample - subprocess.CalledProcessError...
=============================== 1 error in 0.11s ===============================
我尝试过的
- 重置语言环境
- 重新安装postgres
- 重新安装pytest-postgres
- 重新安装psycopg2-binary
我还直接从外壳启动了类似的命令
它不会触发这样的错误:
(myproject) [john@linuxBox ~/myproject]$ initdb --pgdata /tmp/postgresqldata.123450 --username=postgres --auth=trust
The files belonging to this database system will be owned by user "john".
This user must also own the server process.
The database cluster will be initialized with locales
COLLATE: fr_FR.UTF-8
CTYPE: fr_FR.UTF-8
MESSAGES: en_US.UTF-8
MONETARY: fr_FR.UTF-8
NUMERIC: fr_FR.UTF-8
TIME: fr_FR.UTF-8
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "french".
Data page checksums are disabled.
creating directory /tmp/postgresqldata.123450 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Paris
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can Now start the database server using:
pg_ctl -D /tmp/postgresqldata.123450 -l logfile start
问题:
- 下面的两个命令是否等效?
来自pytest :
Command '['/usr/bin/pg_ctl','--username=postgres --auth=trust']'
从外壳:
initdb --pgdata /tmp/postgresqldata.123450 --username=postgres --auth=trust
- 我下一步应该去哪里解决这个问题的任何想法?
谢谢!
编辑1
非常感谢您的评论。
$ locale -a
C
en_US.utf8
fr_FR.utf8
POSIX
pytest-postgresql在2.5.1上:
(myproject) [john@linuxBox ~/myproject]$ cat Pipfile.lock | grep pytest-postgresql -A 6
"pytest-postgresql": {
"hashes": [
"sha256:e2a998c85cd7e917c593292182e523d620018887fadde733c932a70c3825b8bd"
],"index": "pypi","version": "==2.5.1"
},
我在Archlinux上,使用的是postgres 12.4。
编辑2
我想我找到了原因,我可以从shell中重现错误。
在ArchWiki之后,我这样做了:
[postgres@linuxBox ~]$ initdb --locale=C.UTF-8 -E UTF-8 -D /var/lib/postgres/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
initdb: invalid locale name "C.UTF-8"
C.UTF-8似乎是Debian特定的,因此在Archlinux上出错。
此问题似乎密切相关: https://github.com/ClearcodeHQ/pytest-postgresql/issues/338
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)