-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fixed an issue where getpass.getuser()
contained illegal characters for file directories
#8365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed an issue where getpass.getuser()
contained illegal characters for file directories
#8365
Conversation
testing/test_tmpdir.py
Outdated
|
||
|
||
@pytest.fixture | ||
def invalid_get_user(monkeypatch: MonkeyPatch) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this works as I expected, seems OK locally for me, os/agnostic
should be an invalid dirname on win/linux/darwin etc, will revisit! (it appears running from pycharm was A-OK and CLI was A-not-OK)
testing/test_tmpdir.py
Outdated
|
||
@pytest.fixture | ||
def invalid_get_user(monkeypatch: MonkeyPatch) -> None: | ||
monkeypatch.setattr("getpass.getuser", lambda: "os/agnostic") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, you might want to throw a few other characters there too:
monkeypatch.setattr("getpass.getuser", lambda: "os/agnostic") | |
monkeypatch.setattr("getpass.getuser", lambda: "os/:?*agnostic") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, @nicoddemus - any idea why the monkeypatch here is applied when running a single test from pycharm but not when running via pytest testing/tmp_dir.py
or via tox -e py38
etc? Will update this after work later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be because the base temp directory is cached? I suggest to manually reset the base temp directory inside the test, or better yet, just extract the functionality from getbasetemp
into a function and unittest that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
(Note to squash this before we merge it)
closes #8317. It is possible that
getpass.getuser()
can be illegal characters not appropriate for a directory name (platform dependent etc). This PR addresses that by attempting it normally and backing off to use the default-of-unknown
when it occurs. This is consistent whengetuser()
is not Truthy.Appreciate the feed back, thanks again.