Urgent.News

What's breaking now, across thousands of outlets.

Tech

The Failure Message Had a Checkmark. LANG=C Refused to Print It.

Have you ever shipped a pytest suite that looked literate on your laptop and then went illiterate on the server? I spent two days chasing a collector crash that never reproduced on my Mac. I had pinned the same CPython minor and the same requirements lock, which made the gap feel insulting. The tests were not flaky in the usual sense, and the assertion logic itself was boringly deterministic. The…

A pytest suite may print correctly on a developer's laptop but fail on a server due to encoding issues. The problem stems from the fact that some Linux images default to a POSIX C locale, which does not support certain characters like the checkmark. When the suite tries to print a failure message with a checkmark, it raises a UnicodeEncodeError because the server's locale can't handle the character.

This results in the process aborting during the encoding process, rather than when the assertion is evaluated. The issue is exacerbated by cloud images that also boot with LANG=C or LANG=POSIX, causing the sys.stdout.encoding to default to ASCII/ANSI_X3.4-1968. To reproduce the issue, you can create a simple pytest file and run it with different locales.

On a laptop with UTF-8 set, the test will fail normally, but when run on a POSIX C locale server, it will crash during encoding. The key to resolving the issue is to ensure that the locale supports the required characters or to modify the assertion messages to avoid non-ASCII characters.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Tuesday 8 September →