pytest-xvfb is an active pytest plugin, currently at version 3.1.1, that automatically runs tests within a virtual X server like Xvfb, Xephyr, or Xvnc. This enables running graphical user interface (GUI) tests in headless environments, such as continuous integration (CI) servers, without the need for a physical display, preventing windows from unexpectedly popping up during testing.
pip install pytest-xvfbVerified import paths — ran on the pinned version, not inferred.
To use `pytest-xvfb`, simply install it and `pytest`. For most use cases, tests that require a display will automatically run in a virtual framebuffer when `pytest-xvfb` is installed and a suitable backend (like `xvfb` or `xephyr`) is available on the system. You can access the `xvfb` fixture in your tests to get details about the virtual display, or use `@pytest.mark.no_xvfb` to explicitly disable the plugin for a specific test.
Prefer `xvfb` or `xephyr` backends for production CI environments. Check GitHub issues for current status if `xvnc` is critical.
Install and start a lightweight window manager (e.g., `herbstluftwm`) in your CI setup before running tests, especially for complex GUI interactions. Refer to `pytest-qt` documentation for examples.
Ensure `xvfb` (and optionally `xephyr` or `tightvncserver` for other backends) is installed on your system or CI runner via its package manager (e.g., `sudo apt-get install xvfb` on Debian/Ubuntu).
Isolate your test environments as much as possible. Consider dedicated Docker images for CI with specific Qt/GUI library versions, or try to use `--xvfb-backend xephyr` if it helps isolate the display server.