Skip to content

Commit

Permalink
Make tests invariant to LANG setting (#1462)
Browse files Browse the repository at this point in the history
When LANG is set to a non English locale (e.g. de_DE.UTF-8), free and
vmstat will output the text translated and cause the test cases to fail.

Therefore set LANG=C.UTF-8 when calling free or vmstat to always get the
English output.
  • Loading branch information
bdrung authored and giampaolo committed Mar 13, 2019
1 parent 6c71973 commit 3762d0f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def free_swap():
"""Parse 'free' cmd and return swap memory's s total, used and free
values.
"""
out = sh('free -b')
out = sh('free -b', env={"LANG": "C.UTF-8"})
lines = out.split('\n')
for line in lines:
if line.startswith('Swap'):
Expand All @@ -115,7 +115,7 @@ def free_physmem():
# and 'cached' memory which may have different positions so we
# do not return them.
# https://github.com/giampaolo/psutil/issues/538#issuecomment-57059946
out = sh('free -b')
out = sh('free -b', env={"LANG": "C.UTF-8"})
lines = out.split('\n')
for line in lines:
if line.startswith('Mem'):
Expand All @@ -129,7 +129,7 @@ def free_physmem():


def vmstat(stat):
out = sh("vmstat -s")
out = sh("vmstat -s", env={"LANG": "C.UTF-8"})
for line in out.split("\n"):
line = line.strip()
if stat in line:
Expand Down

0 comments on commit 3762d0f

Please sign in to comment.