pytest-xvfb
A pytest plugin to run Xvfb (or Xephyr/Xvnc) for tests.
What it is and what it does
pytest-xvfb is a pytest plugin that integrates virtual display servers (Xvfb, Xephyr, or Xvnc) into your test workflow. When installed, it automatically provides a virtual X11 display for your test suite, preventing GUI windows from appearing during execution and enabling tests to run on headless systems like CI environments. The plugin treats the display server as optional—tests run normally if it's unavailable, but you can enforce its use with command-line flags.
The plugin offers fine-grained control: you can disable Xvfb per-test with the @pytest.mark.no_xvfb decorator, switch backends via --xvfb-backend, or configure display dimensions and color depth in pytest.ini. It exposes a xvfb fixture with attributes like width, height, colordepth, and display number, and supports dynamic disabling through a pytest hook. This makes it useful both for local GUI testing (where you can visually inspect failures) and for CI pipelines where you want to replace wrapper scripts like xvfb-run.
Use it for:
- Run GUI application tests in CI/CD pipelines without a physical display or display server.
- Prevent GUI windows from popping up during local test runs while still testing graphical components.
- Switch between Xvfb, Xephyr, and Xvnc to visually inspect test failures or debug rendering issues.
- Configure virtual display dimensions and color depth per-project via pytest.ini for consistent test environments.
- Replace xvfb-run wrapper scripts in GitHub Actions or similar CI configurations with a pytest plugin.
- Skip specific tests when running under Xvfb using @pytest.mark.no_xvfb for tests that require a real display.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that automatically runs tests with Xvfb (or Xephyr/Xvnc) to provide a virtual display, eliminating GUI windows during test execution and enabling headless testing on systems without a display.
Yes, if you run GUI tests in CI or headless environments. The plugin has low install friction, permissive licensing, no known vulnerabilities, and recent maintenance. It is aging (last release 520 days ago) but still actively maintained. The main caveat is that Xvfb must be installed separately on your system; without it, the plugin degrades gracefully unless you explicitly require it. For projects testing graphical applications, this is a straightforward improvement over manual xvfb-run wrapping.
Install
pytest-xvfb on PyPI
pip
pip install pytest-xvfbuv
uv add pytest-xvfbpoetry
poetry add pytest-xvfbInstalling pytest-xvfb
Before you install
Low install friction with only two runtime dependencies (pytest and pyvirtualdisplay). The package is aging but actively maintained, with a recent release in March 2025 and ongoing repository activity. Supports current Python versions (3.9–3.13).
License in practice
MIT license is permissive and imposes no significant restrictions; you can use, modify, and distribute this package freely in commercial or private projects.
Quickstart
pip install pytest-xvfb
# In your test file:
import pytest
def test_gui_app():
# Tests automatically run with Xvfb when installed
pass
# Run tests:
pytest test_file.py
Xvfb (or Xephyr/Xvnc) must be installed on the system; the plugin treats it as optional and will skip gracefully if unavailable unless --xvfb-backend xvfb is explicitly set. Requires Python 3.9 or later.
Verify before relying
- Whether Xvnc support is production-ready given the noted incompatibilities with PyVirtualDisplay and Ubuntu 22.04's tightvncserver.
- Performance overhead of running tests under Xvfb compared to native execution.
- Compatibility with non-Linux systems (plugin is OS-independent but Xvfb availability varies).
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pytest, pyvirtualdisplay |
| Maintenance | aging — 520 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 229,227/month — #9,136 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_xvfb-3.1.1-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
PyVirtualDisplayWraps Xvfb, Xephyr, and Xvnc to create virtual…
permissive · top 5,000 on PyPI
xvfbwrapperManages headless X11 virtual displays using…
permissive · top 5,000 on PyPI
sbvirtualdisplayProvides a virtual display wrapper for running…
permissive · top 15,000 on PyPI
pytest-cythonA pytest plugin that runs doctests embedded in…
unclear · top 15,000 on PyPI
pytest-qtpytest-qt is a pytest plugin that provides…
permissive · top 5,000 on PyPI
pytest-icdiffA pytest plugin that replaces default assertion…
permissive · top 5,000 on PyPI
pytest-richA pytest plugin that uses rich to format and…
permissive · top 15,000 on PyPI
pytest-error-for-skipsA pytest plugin that converts skipped tests…
permissive · top 15,000 on PyPI
pytest-loggingA pytest plugin that configures Python logging…
permissive · top 15,000 on PyPI
pytest-regressionsProvides pytest fixtures for writing regression…
permissive · top 5,000 on PyPI