skillfed

pytest-xvfb

A pytest plugin to run Xvfb (or Xephyr/Xvnc) for tests.

pytest-xvfb v3.1.1 229.2K downloads/30d#9,136 on PyPI76
Permissive license MIT AGING released

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-xvfb

uv

uv add pytest-xvfb

poetry

poetry add pytest-xvfb

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing

Tags

pytest virtual displayheadless GUI testingxvfb pytest pluginCI display automationpytest xvfb xephyrheadless test runnervirtual framebuffer testing
gui-testingci-automationheadless

More Testing packages