Skip to content

Commit 846be9d

Browse files
committed
TST: don't assume test user is OS user
mock getpwnam to always return result for current user since test user may well no exist In particular, JupyterHub 5 test utilities no longer create a test user with the running user's name
1 parent d5c4617 commit 846be9d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

batchspawner/tests/test_spawners.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
"""Test BatchSpawner and subclasses"""
22

33
import asyncio
4+
import pwd
45
import re
56
import time
7+
from getpass import getuser
8+
from unittest import mock
69

710
import pytest
811
from jupyterhub import orm
@@ -17,6 +20,15 @@
1720
testport = 54321
1821

1922

23+
@pytest.fixture(autouse=True)
24+
def _always_get_my_home():
25+
# pwd.getbwnam() is always called with the current user
26+
# ignoring the requested name, which usually doesn't exist
27+
getpwnam = pwd.getpwnam
28+
with mock.patch.object(pwd, "getpwnam", lambda name: getpwnam(getuser())):
29+
yield
30+
31+
2032
class BatchDummy(BatchSpawnerRegexStates):
2133
exec_prefix = ""
2234
batch_submit_cmd = Unicode("cat > /dev/null; echo " + testjob)

0 commit comments

Comments
 (0)