Skip to main content

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


Installation

You can install “pytest-xvfb” via pip from PyPI:

$ pip install pytest-xvfb

Usage

With Xvfb and the plugin installed, your testsuite automatically runs with Xvfb. This allows tests to be run without windows popping up during GUI tests or on systems without a display (like a CI).

The plugin sees Xvfb being installed as “optional”, since the tests can still run without it installed. If it’s unavailable, it will show an informational message, if on Linux and a DISPLAY is available. When using --xvfb-backend xvfb, this message will turn into a hard error instead.

If you’re currently using xvfb-run in something like a GitHub Actions YAML file simply remove the wrapper and install this plugin instead - then you’ll also have the benefits of Xvfb locally.

Features

You can pass --no-xvfb to explicitly turn off Xvfb (e.g. to visually inspect a failure).

With --xvfb-backend xephyr or --xvfb-backend xvnc, you can use Xephyr or Xvnc in place of Xvfb, e.g. to visually inspect failures.

NOTE: Support for xvnc is currently experimental and not tested on CI, due to incompatibilities with PyVirtualDisplay and Ubuntu 22.04’s tightvncserver.

You can mark tests with @pytest.mark.no_xvfb to skip them when they’re running with Xvfb.

By implementing the pytest_xvfb_disable(config: pytest.Config) pytest hook, you can dynamically decide whether pytest-xvfb should be disabled (by returning True from such a hook).

A xvfb fixture is available with the following attributes:

  • width: The configured width of the screen.

  • height: The configured height of the screen.

  • colordepth: The configured colordepth of the screen.

  • args: The arguments to be passed to Xvfb.

  • display: The display number (as int) which is used.

  • backend: Either None (Xvfb), "xvfb", "xephyr", or "xvnc".

In a pytest.ini, xvfb_width, xvfb_height, xvfb_colordepth and xvfb_args can be used to configure the respective values. In addition, xvfb_xauth can be set to true to generate an Xauthority token.

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-xvfb” is free and open source software

Thanks

This pytest plugin was generated with Cookiecutter along with @hackebrot’s Cookiecutter-pytest-plugin template.

Thanks to @cgoldberg for xvfbwrapper which was the inspiration for this project.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Metadata

Release files for pytest-xvfb 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-xvfb 3.1.1
File Size Uploaded
pytest_xvfb-3.1.1.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-xvfb 3.1.1
File Interpreter ABI Platform
pytest_xvfb-3.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / pytest_xvfb-3.1.1.tar.gz

Download URL pytest_xvfb-3.1.1.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
90593634427d974b272e845793e4533f5b827c9d84c051879013624504175e44
BLAKE2b-256 checksum
How to use checksums
b6ceb3444c98eab123b7348d55d4705c2f1095a6bdf8dae85bc6a34ab5222845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 12, 2025.

Transparency log

Release files / pytest_xvfb-3.1.1-py3-none-any.whl

Download URL pytest_xvfb-3.1.1-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3270f91417cfa0652b7c5a90e93a676e3a80bec12ccbd20cae3b42511e4aba98
BLAKE2b-256 checksum
How to use checksums
266e859b1e496671fb236153c2caed519301c53f7cf3dfcaac809caae695b5a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 12, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page