Closed liZe closed 4 years ago
I think this makes sense, but I'm still curious where the translated strings come from.
They’re from the PostgreSQL server. The locale can be changed with the lc_messages
value in postgresql.conf
. If the value is not set, PostgreSQL uses the locale environment variable instead. I get the messages in psql
too, they’re not related to Python libraries at all, and changing the locale for the tests doesn’t fix the problem.
PostgreSQL initdb
command has an --lc-messages=LOCALE
option, so I suppose that it’s possible to force the locale for a given database. A SQL query is also available for the administrator account, but it only works for the current session as far as I can tell.
My value has always been fr_FR
as far as I can remember, no idea why the tests suddenly started to fail. Setting lc_messages
in the PostgreSQL container (if it’s not already done) is probably the easiest way to have consistent results.
Oh interesting. I didn't think the server would send messages at all. I'd think it would send error codes and the client would provide strings for those. That does seem more difficult to handle since the database setup is not part of the test fixture.
I think this makes sense, but I'm still curious where the translated strings come from. If you run
LC_ALL=C.UTF-8 pytest
(or whatever the test command is) do you still have this issue? Because another way to approach this is to make sure the testing environment is consistent, and one thing to do there is to set a consistent locale. This can be done in a CI recipe, but it could also be done here using a wrapper script or something in pytest. https://subscription.packtpub.com/book/programming/9781789347562/4/ch04lvl1sec29/using-marks-from-fixtures is an example of adding a fixture to set the locale.