Skip to content

Commit

Permalink
TST: don't assume test user is OS user
Browse files Browse the repository at this point in the history
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
  • Loading branch information
minrk committed Mar 8, 2024
1 parent d5c4617 commit c7e61ef
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions batchspawner/tests/test_spawners.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Test BatchSpawner and subclasses"""

import asyncio
import os
import pwd
import re
import time
from unittest import mock

import pytest
from jupyterhub import orm
Expand All @@ -17,6 +20,15 @@
testport = 54321


@pytest.fixture(autouse=True)
def _always_get_my_home():
# pwd.getbwnam() is always called with the current user
# ignoring the requested name, which usually doesn't exist
getpwnam = pwd.getpwnam
with mock.patch.object(pwd, "getpwnam", lambda name: getpwnam(os.getlogin())):
yield


class BatchDummy(BatchSpawnerRegexStates):
exec_prefix = ""
batch_submit_cmd = Unicode("cat > /dev/null; echo " + testjob)
Expand Down

0 comments on commit c7e61ef

Please sign in to comment.