diff --git a/src/ansys/dynamicreporting/core/utils/filelock.py b/src/ansys/dynamicreporting/core/utils/filelock.py index f5d54ed24..7fe8a17f4 100644 --- a/src/ansys/dynamicreporting/core/utils/filelock.py +++ b/src/ansys/dynamicreporting/core/utils/filelock.py @@ -30,6 +30,7 @@ # Modules # ------------------------------------------------ import functools +import getpass import logging import os import threading @@ -473,7 +474,7 @@ def nexus_file_lock(filename: str) -> BaseFileLock: # We will consider two pathnames: # 1) the original pathname # 2) replace the original filename directory with tempfile.gettempdir() - base_filename = os.path.basename(filename) + "." + os.getlogin() + base_filename = os.path.basename(filename) + "." + getpass.getuser() lcl_filename = os.path.join(tempfile.gettempdir(), base_filename) # if we are on Linux and the target filename is on an NFS drive diff --git a/tests/test_filelock.py b/tests/test_filelock.py index 8a6207e4c..e552081ed 100755 --- a/tests/test_filelock.py +++ b/tests/test_filelock.py @@ -111,12 +111,11 @@ def test_soft(request) -> None: def test_nexus_filelock(request) -> None: test_path = join(request.fspath.dirname, "test_data") tmp_file = join(test_path, "n_lock.txt") - try: - success = type(fl.nexus_file_lock(filename=tmp_file)) is fl.FileLock - except OSError: # Error due to not being able to get os.getlogin() on the machine - success = True - else: - success = False - if "win" in platform.system().lower(): - success = True - assert success + + lock = fl.nexus_file_lock(filename=tmp_file) + + # Debug info + print("Resolved lock type:", type(lock)) + print("Expected FileLock type:", fl.FileLock) + + assert isinstance(lock, fl.FileLock)