KeyError: 'USER' When Running Nose Tests #331

Closed
jlec opened this Issue Oct 2, 2015 · 6 comments

Comments

Projects
None yet
3 participants
@jlec

jlec commented Oct 2, 2015

======================================================================
ERROR: test_bogus_group (tests.ext.daemon_tests.DaemonExtTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.3/site-packages/nose/tools/nontrivial.py", line 60, in newfunc
    func(*arg, **kw)
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2/tests/ext/daemon_tests.py", line 79, in test_bogus_group
    env = ext_daemon.Environment()
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/ext/ext_daemon.py", line 220, in __init__
    self.user = kw.get('user', os.environ['USER'])
  File "/usr/lib64/python3.3/os.py", line 676, in __getitem__
    raise KeyError(key) from None
KeyError: 'USER'

======================================================================
ERROR: test_bogus_user (tests.ext.daemon_tests.DaemonExtTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.3/site-packages/nose/tools/nontrivial.py", line 60, in newfunc
    func(*arg, **kw)
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2/tests/ext/daemon_tests.py", line 66, in test_bogus_user
    env = ext_daemon.Environment()
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/ext/ext_daemon.py", line 220, in __init__
    self.user = kw.get('user', os.environ['USER'])
  File "/usr/lib64/python3.3/os.py", line 676, in __getitem__
    raise KeyError(key) from None
KeyError: 'USER'

======================================================================
ERROR: test_daemon_not_passed (tests.ext.daemon_tests.DaemonExtTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2/tests/ext/daemon_tests.py", line 110, in test_daemon_not_passed
    app.setup()
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/core/foundation.py", line 750, in setup
    for res in hook.run('post_setup', self):
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/core/hook.py", line 114, in run
    res = hook[2](*args, **kwargs)
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/ext/ext_daemon.py", line 393, in extend_app
    user = pwd.getpwnam(os.environ['USER'])
  File "/usr/lib64/python3.3/os.py", line 676, in __getitem__
    raise KeyError(key) from None
KeyError: 'USER'

======================================================================
ERROR: test_pid_exists (tests.ext.daemon_tests.DaemonExtTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.3/site-packages/nose/tools/nontrivial.py", line 60, in newfunc
    func(*arg, **kw)
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2/tests/ext/daemon_tests.py", line 43, in test_pid_exists
    env = ext_daemon.Environment(pid_file=tmpfile)
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/ext/ext_daemon.py", line 220, in __init__
    self.user = kw.get('user', os.environ['USER'])
  File "/usr/lib64/python3.3/os.py", line 676, in __getitem__
    raise KeyError(key) from None
KeyError: 'USER'

======================================================================
ERROR: test_switch (tests.ext.daemon_tests.DaemonExtTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2/tests/ext/daemon_tests.py", line 25, in test_switch
    env = ext_daemon.Environment()
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/ext/ext_daemon.py", line 220, in __init__
    self.user = kw.get('user', os.environ['USER'])
  File "/usr/lib64/python3.3/os.py", line 676, in __getitem__
    raise KeyError(key) from None
KeyError: 'USER'

======================================================================
ERROR: test_switch_with_pid (tests.ext.daemon_tests.DaemonExtTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2/tests/ext/daemon_tests.py", line 31, in test_switch_with_pid
    env = ext_daemon.Environment(pid_file=tmpfile)
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/ext/ext_daemon.py", line 220, in __init__
    self.user = kw.get('user', os.environ['USER'])
  File "/usr/lib64/python3.3/os.py", line 676, in __getitem__
    raise KeyError(key) from None
KeyError: 'USER'

======================================================================
FAIL: test_daemon (tests.ext.daemon_tests.DaemonExtTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2/tests/ext/daemon_tests.py", line 105, in test_daemon
    self.eq(p.exitcode, 0)
  File "/var/tmp/portage/dev-python/cement-2.6.2/work/cement-2.6.2-python3_3/lib/cement/utils/test.py", line 80, in eq
    return eq(a, b, msg)
nose.proxy.AssertionError: 1 != 0
>>  raise AssertionError(None or "%r != %r" % (1, 0))
@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Oct 2, 2015

Member

@jlec can you please provide the following:

  • OS Version
  • Python Version
  • Cement Version

Thanks!

Member

derks commented Oct 2, 2015

@jlec can you please provide the following:

  • OS Version
  • Python Version
  • Cement Version

Thanks!

@derks derks changed the title from ERROR: test_bogus_group (tests.ext.daemon_tests.DaemonExtTestCase) to KeyError: 'USER' When Running Nose Tests Oct 2, 2015

@jlec

This comment has been minimized.

Show comment
Hide comment
@jlec

jlec Oct 3, 2015

@derks
Linux 64bit
python 2.7, 3.3, 3.4 and pypy
cement-2.6.2

jlec commented Oct 3, 2015

@derks
Linux 64bit
python 2.7, 3.3, 3.4 and pypy
cement-2.6.2

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Oct 5, 2015

Member

Is this on Ubuntu? I've had issues with Ubuntu not setting the USER environment variable. I assume the following fixes your issues:

$ export USER='your_username'

Where your_username is obviously the user you are logged in as.

Member

derks commented Oct 5, 2015

Is this on Ubuntu? I've had issues with Ubuntu not setting the USER environment variable. I assume the following fixes your issues:

$ export USER='your_username'

Where your_username is obviously the user you are logged in as.

@derks derks added this to the 2.8.0 Stable milestone Oct 5, 2015

@derks derks self-assigned this Oct 5, 2015

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Oct 5, 2015

Member

Marking this as a bug... ext_daemon is accessing os.environ['USER'] which fails if $USER isn't set. Alternative means would be to use os.getlogin() which doesn't rely on the environment variable. Will push a fix to git/master shortly.

Member

derks commented Oct 5, 2015

Marking this as a bug... ext_daemon is accessing os.environ['USER'] which fails if $USER isn't set. Alternative means would be to use os.getlogin() which doesn't rely on the environment variable. Will push a fix to git/master shortly.

derks added a commit that referenced this issue Oct 5, 2015

@derks derks closed this Oct 5, 2015

@Vafa-Andalibi

This comment has been minimized.

Show comment
Hide comment
@Vafa-Andalibi

Vafa-Andalibi Apr 20, 2017

Just out of curiosity, doesn't os.getlogin() use LOGNAME environment variable?

Just out of curiosity, doesn't os.getlogin() use LOGNAME environment variable?

@derks

This comment has been minimized.

Show comment
Hide comment
@derks

derks Apr 20, 2017

Member

@Vafa-Andalibi per the doc:

Return the name of the user logged in on the controlling terminal of the process. For most purposes, it is more useful to use the environment variable LOGNAME to find out who the user is, or pwd.getpwuid(os.getuid())[0] to get the login name of the process’s real user id.

So it sounds like it is saying that it is recommended to use the LOGNAME environment variable, not that it returns that environment variable.

Member

derks commented Apr 20, 2017

@Vafa-Andalibi per the doc:

Return the name of the user logged in on the controlling terminal of the process. For most purposes, it is more useful to use the environment variable LOGNAME to find out who the user is, or pwd.getpwuid(os.getuid())[0] to get the login name of the process’s real user id.

So it sounds like it is saying that it is recommended to use the LOGNAME environment variable, not that it returns that environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment