Skip to content

Commit aa17841

Browse files
yannrichetclaude
andcommitted
Replace os.getenv('USER') with getpass.getuser() for better cross-platform compatibility
Use getpass.getuser() instead of os.getenv('USER') in SSH tests to ensure compatibility with GitHub Actions and other CI environments where USER environment variable may not be set. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9ca4b99 commit aa17841

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
import socket
99
import subprocess
10+
import getpass
1011
from pathlib import Path
1112

1213

@@ -66,7 +67,7 @@ def is_ssh_server_available():
6667
"-o", "StrictHostKeyChecking=no",
6768
"-o", "UserKnownHostsFile=/dev/null",
6869
"-o", "LogLevel=ERROR",
69-
f"{os.getenv('USER')}@localhost",
70+
f"{getpass.getuser()}@localhost",
7071
"exit 0"
7172
],
7273
capture_output=True,

tests/test_ssh_many_cases.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import time
1515
from pathlib import Path
1616
import pytest
17+
import getpass
1718
from conftest import SSH_AVAILABLE
1819

1920
# Check if paramiko is available
@@ -128,7 +129,7 @@ def test_ssh_many_cases_localhost():
128129
"-o", "UserKnownHostsFile=/dev/null",
129130
"-o", "ConnectTimeout=5",
130131
"-o", "LogLevel=ERROR",
131-
f"{os.getenv('USER')}@localhost",
132+
f"{getpass.getuser()}@localhost",
132133
"echo 'SSH OK'"
133134
],
134135
capture_output=True,
@@ -193,7 +194,7 @@ def test_ssh_many_cases_localhost():
193194
from fz import fzr
194195

195196
# Build SSH calculator URL
196-
ssh_calculator = f"ssh://{os.getenv('USER')}@localhost/bash {calc_script.resolve()}"
197+
ssh_calculator = f"ssh://{getpass.getuser()}@localhost/bash {calc_script.resolve()}"
197198

198199
print(f" Calculator: {ssh_calculator}")
199200

@@ -455,7 +456,7 @@ def test_ssh_many_cases_many_localhost():
455456
"-o", "UserKnownHostsFile=/dev/null",
456457
"-o", "ConnectTimeout=5",
457458
"-o", "LogLevel=ERROR",
458-
f"{os.getenv('USER')}@localhost",
459+
f"{getpass.getuser()}@localhost",
459460
"echo 'SSH OK'"
460461
],
461462
capture_output=True,
@@ -520,7 +521,7 @@ def test_ssh_many_cases_many_localhost():
520521
from fz import fzr
521522

522523
# Build SSH calculator URL
523-
ssh_calculator = [f"ssh://{os.getenv('USER')}@localhost/bash {calc_script.resolve()}"]*3
524+
ssh_calculator = [f"ssh://{getpass.getuser()}@localhost/bash {calc_script.resolve()}"]*3
524525

525526
print(f" Calculators: {ssh_calculator}")
526527

tests/test_ssh_perfectgaz.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import time
2222
from pathlib import Path
2323
import pytest
24+
import getpass
2425
from fz import fzr
2526
from conftest import SSH_AVAILABLE
2627

@@ -151,7 +152,7 @@ def test_perfectgaz_via_ssh_localhost():
151152
"-o", "UserKnownHostsFile=/dev/null",
152153
"-o", "ConnectTimeout=5",
153154
"-o", "LogLevel=ERROR",
154-
f"{os.getenv('USER')}@localhost",
155+
f"{getpass.getuser()}@localhost",
155156
"echo 'SSH OK'"
156157
],
157158
capture_output=True,
@@ -212,7 +213,7 @@ def test_perfectgaz_via_ssh_localhost():
212213
print("\n6. Running fzr with SSH calculator...")
213214

214215
# Build SSH calculator URL
215-
ssh_calculator = f"ssh://{os.getenv('USER')}@localhost/bash " + str(calc_script.resolve()) #./PerfectGazPressure.sh"
216+
ssh_calculator = f"ssh://{getpass.getuser()}@localhost/bash " + str(calc_script.resolve()) #./PerfectGazPressure.sh"
216217

217218
print(f"Calculator: {ssh_calculator}")
218219

0 commit comments

Comments
 (0)