Git Product home page Git Product logo

Comments (4)

fohrloop avatar fohrloop commented on July 17, 2024

I checked the environment variables with my current terminal (myenv) and inside the tox pytest process (testenv). These are the common environment variables:

key          my                                                  test
-----------  --------------------------------------------------  --------------------------------------------------
LANG         en_US.UTF-8                                         en_US.UTF-8
TERM         xterm-256color                                      xterm-256color
PATH         /home/niko/.local/bin:/home/niko/venvs/wakepy/bin:  /home/niko/tmp/repos/wakepy/.tox/py310/bin:/home/n
VIRTUAL_ENV  /home/niko/venvs/wakepy                             /home/niko/tmp/repos/wakepy/.tox/py310
HOME         /home/niko                                          /home/niko

These are the environment variables specific to the test environment:

key                            test
-----------------------------  -----------------------------------------------------------------------------
LINES                          26
TOX_PACKAGE                    /home/niko/tmp/repos/wakepy/.tox/.tmp/package/5/wakepy-0.6.0-py3-none-any.whl
TOX_ENV_NAME                   py310
PYTHONHASHSEED                 424929341
PYTHONIOENCODING               utf-8
TOX_ENV_DIR                    /home/niko/tmp/repos/wakepy/.tox/py310
PYTEST_CURRENT_TEST            tests/test_wakepy.py::test_import_set_and_unset_keeepawake (call)
COLUMNS                        156
PIP_DISABLE_PIP_VERSION_CHECK  1
TOX_WORK_DIR                   /home/niko/tmp/repos/wakepy/.tox

The test environment is really missing the environment variable DBUS_SESSION_BUS_ADDRESS. It is set on my current terminal to:

$ echo $DBUS_SESSION_BUS_ADDRESS
unix:path=/run/user/1000/bus

from wakepy.

fohrloop avatar fohrloop commented on July 17, 2024

Wakepy 0.6.0 uses by default the Inhibit/Uninhibit methods of the org.freedesktop.Screensaver interface of the session D-Bus.

Reading at Well-known Message Bus Instances from D-Bus Specification:

The address of the login session message bus is given in the DBUS_SESSION_BUS_ADDRESS environment variable.

When using a breakpoint inside the test (tox+pytest), I can see that the dbus is running:

(Pdb) os.system('ps -x | grep dbus')
   1107 ?        Ss     0:03 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
   1246 ?        S      0:00 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 11 --address=un
  14110 pts/0    S+     0:00 sh -c ps -x | grep dbus
  14113 pts/0    S+     0:00 grep dbus
0

but there is no DBUS_SESSION_BUS_ADDRESS environment variable:

(Pdb) pprint.pprint(dict(os.environ))
{'COLUMNS': '151',
 'HOME': '/home/niko',
 'LANG': 'en_US.UTF-8',
 'LINES': '15',
 'PATH': '/home/niko/tmp/repos/wakepy/.tox/py310/bin:/home/niko/.local/bin:/home/niko/venvs/wakepy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin',
 'PIP_DISABLE_PIP_VERSION_CHECK': '1',
 'PYTEST_CURRENT_TEST': 'tests/test_wakepy.py::test_import_set_and_unset_keeepawake '
                        '(call)',
 'PYTHONHASHSEED': '1404011170',
 'PYTHONIOENCODING': 'utf-8',
 'TERM': 'xterm-256color',
 'TOX_ENV_DIR': '/home/niko/tmp/repos/wakepy/.tox/py310',
 'TOX_ENV_NAME': 'py310',
 'TOX_PACKAGE': '/home/niko/tmp/repos/wakepy/.tox/.tmp/package/11/wakepy-0.6.0-py3-none-any.whl',
 'TOX_WORK_DIR': '/home/niko/tmp/repos/wakepy/.tox',
 'VIRTUAL_ENV': '/home/niko/tmp/repos/wakepy/.tox/py310'}

(Pdb) os.environ['DBUS_SESSION_BUS_ADDRESS']
*** KeyError: 'DBUS_SESSION_BUS_ADDRESS'

from wakepy.

fohrloop avatar fohrloop commented on July 17, 2024

This can be fixed with adding DBUS_SESSION_BUS_ADDRESS to pass_env of the corresponding tox.ini section. For example:

[testenv]
description = run the tests with pytest
package = wheel
wheel_build_env = .pkg
pass_env = 
    DBUS_SESSION_BUS_ADDRESS

This way tox will pass the environment variable DBUS_SESSION_BUS_ADDRESS which contains the session D-Bus address, to the process running the test.

from wakepy.

fohrloop avatar fohrloop commented on July 17, 2024

The reason for the exception is now clear. User should always pass the DBUS_SESSION_BUS_ADDRESS environment variable to subprocess if using wakepy with dbus method in subprocesses. I'll close this one since there are these new tickets that should make usage of wakepy more convenient:

I'm also considering if there should be some automation trying to get the DBUS_SESSION_BUS_ADDRESS from the parent python process or the dbus-daemon process. but that seems a bit hacky.

from wakepy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.