Skip to content
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

[Bug] os.environ["USER"] is set unconditionally in hydra/hydra/test_utils/test_utils.py #1059

Closed
ajw1980 opened this issue Oct 14, 2020 · 5 comments · Fixed by #1060
Closed
Labels
bug Something isn't working
Milestone

Comments

@ajw1980
Copy link

ajw1980 commented Oct 14, 2020

Since os.environ["USER"] is set and hydra-core installs a pytest plugin any other pytest tests that use the $USER environment variable will get overridden to use "test_user" as the user. I think this should probably be a conditional check or something. We had a test start failing that was using $USER and it took some time to figure out why that was being set to test_user.

@ajw1980 ajw1980 added the bug Something isn't working label Oct 14, 2020
@shagunsodhani
Copy link
Contributor

Relevant line: https://github.com/facebookresearch/hydra/blob/master/hydra/test_utils/test_utils.py#L30

Making a PR that checks if the variable is already set.

@shagunsodhani
Copy link
Contributor

Ideally we should unset the variable (if we do set it up).

@omry
Copy link
Collaborator

omry commented Oct 14, 2020

Can you provide a repro? I want to see why this is even being called for you.

What are you doing that gets the USER overwritten?
Generally speaking, test_utils is for internal usage and I am not expecting people to use it from external projects.

@ajw1980
Copy link
Author

ajw1980 commented Oct 14, 2020

Simple test case to check the user. First pytest without extra options so hydra_pytest is enabled. Second test with hydra_pytest disabled on the command line

[andy.wettstein@tx1-lsbd445 mytest]$ cat test_user.py
import os

def test_user():
    assert os.environ["USER"] == 'andy.wettstein'
[andy.wettstein@tx1-lsbd445 mytest]$ pytest
======================================================================= test session starts =======================================================================platform linux -- Python 3.7.7, pytest-5.1.1, py-1.8.0, pluggy-0.13.0
rootdir: /home/andy.wettstein/mytest
plugins: cov-2.8.1, datadir-1.3.1, flake8-1.0.4, regressions-2.0.1, forked-1.2.0, parallel-0.1.0, xdist-1.32.0, remotedata-0.3.2, hydra-core-1.0.3
collected 1 item

test_user.py F                                                                                                                                              [100%]

============================================================================ FAILURES =============================================================================____________________________________________________________________________ test_user ____________________________________________________________________________

    def test_user():
>       assert os.environ["USER"] == 'andy.wettstein'
E       AssertionError: assert 'test_user' == 'andy.wettstein'
E         - test_user
E         + andy.wettstein

test_user.py:4: AssertionError
======================================================================== 1 failed in 0.19s ========================================================================


[andy.wettstein@tx1-lsbd445 mytest]$ pytest -p no:hydra_pytest
======================================================================= test session starts =======================================================================platform linux -- Python 3.7.7, pytest-5.1.1, py-1.8.0, pluggy-0.13.0
rootdir: /home/andy.wettstein/mytest
plugins: cov-2.8.1, datadir-1.3.1, flake8-1.0.4, regressions-2.0.1, forked-1.2.0, parallel-0.1.0, xdist-1.32.0, remotedata-0.3.2
collected 1 item

test_user.py .                                                                                                                                              [100%]

======================================================================== 1 passed in 0.08s ========================================================================

@omry
Copy link
Collaborator

omry commented Oct 14, 2020

Gotcha. so as soon as Hydra is installed it overwrites the USER in pytest tests via the plugin. that's nasty and definitely unintended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants