| 1 | diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py |
| 2 | --- a/src/_pytest/tmpdir.py |
| 3 | +++ b/src/_pytest/tmpdir.py |
| 4 | @@ -115,7 +115,12 @@ def getbasetemp(self) -> Path: |
| 5 | # use a sub-directory in the temproot to speed-up |
| 6 | # make_numbered_dir() call |
| 7 | rootdir = temproot.joinpath(f"pytest-of-{user}") |
| 8 | - rootdir.mkdir(exist_ok=True) |
| 9 | + try: |
| 10 | + rootdir.mkdir(exist_ok=True) |
| 11 | + except OSError: |
| 12 | + # getuser() likely returned illegal characters for the platform, use unknown back off mechanism |
| 13 | + rootdir = temproot.joinpath("pytest-of-unknown") |
| 14 | + rootdir.mkdir(exist_ok=True) |
| 15 | basetemp = make_numbered_dir_with_cleanup( |
| 16 | prefix="pytest-", root=rootdir, keep=3, lock_timeout=LOCK_TIMEOUT |
| 17 | ) |