Skip to content

Make tmpdir more resilient in case environment variables required by getpass are missing #1013

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

Merged
merged 4 commits into from
Sep 16, 2015

Conversation

nicoddemus
Copy link
Member

Fix #1010

@nicoddemus
Copy link
Member Author

cc @alex

@RonnyPfannschmidt
Copy link
Member

please move the username getting into a utility function and unit-test that

@nicoddemus
Copy link
Member Author

please move the username getting into a utility function and unit-test that

Good idea, done.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
temproot = py.path.local.get_temproot()
rootdir = temproot.join('pytest-of-%s' % getpass.getuser())
rootdir = temproot.join('pytest-of-%s' % get_user())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually looks odd to me in combination with using a fixed pytest-tox. If you have a Jenkins machine that executes multiple tox runs is this not bound to lead to bad interactions?

What about simply not creating a subdir but using the "slow" make_numbered_dir on the temproot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a Jenkins machine that executes multiple tox runs is this not bound to lead to bad interactions?

Hmm I don't think so, because py.path.local.make_numbered_dir is atomic, and will correctly create a separate directory for each invocation... pytest-tox will only be used when running py.test from inside tox without passing %USERNAME on Windows.

What about simply not creating a subdir but using the "slow" make_numbered_dir on the temproot?

That's how the code was written originally, but it was changed as an optimization. From the CHANGELOG:

  • optimized tmpdir fixture initialization, which should make test sessions
    faster (specially when using pytest-xdist). The only visible effect
    is that now pytest uses a subdirectory in the $TEMP directory for all
    directories created by this fixture (defaults to $TEMP/pytest-$USER).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i was unclear. I meant not creating a subdir if we don't have a username.

Suppose two users on a Windows machine where each executes tox which executes pytest. Will they not conflict on creating pytest-tox at the temproot by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i was unclear. I meant not creating a subdir if we don't have a username.

Oh I see, thanks for clarifying.

Suppose two users on a Windows machine where each executes tox which executes pytest. Will they not conflict on creating pytest-tox at the temproot by default?

Hmm I don't see how this could be a problem... make_numbered_dir will guarantee that each process gets its own unique directory, the fact that they share the same rootdir shouldn't matter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If two processes from different accounts concurrently run without a USERNAME setting then this ensure or the subsequent make_numbered_dir calls can run into permission problems, no?

Oh that's a good point! 😅

I will follow your advice and fallback to not using a root directory at all if there's no user name.

@alex
Copy link
Contributor

alex commented Sep 16, 2015

FWIW, an alternate solution might be to just have tox include USERNAME in passenv, not sure how you would feel about that.

temproot = py.path.local.get_temproot()
rootdir = temproot.join('pytest-of-%s' % getpass.getuser())
rootdir = temproot.join('pytest-of-%s' % get_user())
rootdir.ensure(dir=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If two processes from different accounts concurrently run without a USERNAME setting then this ensure or the subsequent make_numbered_dir calls can run into permission problems, no?

@hpk42
Copy link
Contributor

hpk42 commented Sep 16, 2015

Alex: IIRC not having a username can even appear in non-tox runs (debian or some other build sandboxed environments). Also people might be running mixtures of old/new tox/pytest versions given they are both deployed widely. So i think it makes sense to fix it here and independently consider tox adding USERNAME/USER to passenv.

@alex
Copy link
Contributor

alex commented Sep 16, 2015

Ok, fair enough!

On Wed, Sep 16, 2015 at 3:30 PM, hpk42 [email protected] wrote:

Alex: IIRC not having a username can even appear in non-tox runs (debian
or some other build sandboxed environments). Also people might be running
mixtures of old/new tox/pytest versions given they are both deployed
widely. So i think it makes sense to fix it here and independently consider
tox adding USERNAME/USER to passenv.


Reply to this email directly or view it on GitHub
#1013 (comment).

"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084

hpk42 added a commit that referenced this pull request Sep 16, 2015
Make tmpdir more resilient in case environment variables required by getpass are missing
@hpk42 hpk42 merged commit 886ac82 into pytest-dev:master Sep 16, 2015
@nicoddemus nicoddemus deleted the issue1010 branch September 16, 2015 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants