nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
2.98k stars 427 forks source link

Zero coverage of process spawned by dogtail #1786

Closed olumide-x closed 3 months ago

olumide-x commented 4 months ago

Our team uses dogtail to GUI test our application but unfortunately we've never been able to get any coverage from these tests.

I've prepared a simple test demonstrating this scenario. (Create/download these files into the same directory.)

  1. my_app.py -- a simple GTK Python application
  2. test_my_app.py -- a dogtail script that launches the above GTK Python application
  3. .coveragerc -- .coveragerc file.

Other steps I took to run the above scripts on Ubuntu LTS 22.04:

I don't know if I am doing something wrong, or this is a missing feature or a bug.

dogtail is based on subprocess so I've added concurrency = multiprocessing to the .coveragerc file.


Here are some packages/steps that may be needed in order to setup GTK, GTK Python and dogtail (extracted from our pipeline)

- apt-get update && apt-get install dbus-x11 libcairo2-dev libgirepository1.0-dev libgtk-3-dev at-spi2-core python3-pyatspi python3-dogtail gnome-icon-theme gsettings-desktop-schemas -y
- pip install pycairo PyGObject

- eval $(dbus-launch --sh-syntax)
- gsettings set org.gnome.desktop.interface toolkit-accessibility true
# Poor man's fix. (pyatspi and dogtail install to dist-packages on Ubuntu. )
- ln -s /usr/lib/python3/dist-packages/pyatspi /usr/local/lib/python3.10/site-packages/pyatspi
- ln -s /usr/lib/python3/dist-packages/dogtail /usr/local/lib/python3.10/site-packages/dogtail

Caveat: Run on dogtail scripts on X-Windows. dogtail does not run well on Wayland.

(I posted a version of this question on stackflow just over a month ago but without a working example. Hopefully a reproducible example will help make the problem clearer.)

olumide-x commented 4 months ago

@nedbat @marcgibbons Are you able to advise on this issue?

devdanzin commented 4 months ago

my_app.py 17 0 100%

This seems to indicate you have 100% coverage of my_app.py?

olumide-x commented 4 months ago

my_app.py 17 0 100%

This seems to indicate you have 100% coverage of my_app.py?

That's a typo. I've just rerun the test and edited the OP with the correct stats.

olumide-x commented 3 months ago

Problem solved.

I was running the test with sudo, i.e.

sudo xvfb-run coverage run --rcfile=.coveragerc -m pytest test_my_app.py

As such the environment variable COVERAGE_PROCESS_START was not preserved.

sudo -E xvfb-run coverage run --rcfile=.coveragerc -m pytest test_my_app.py

Fixes the problem.