Skip to main content

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

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_xvfb-3.1.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

pytest_xvfb-3.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_xvfb-3.1.1.tar.gz.

File metadata

  • Download URL: pytest_xvfb-3.1.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_xvfb-3.1.1.tar.gz
Algorithm Hash digest
SHA256 90593634427d974b272e845793e4533f5b827c9d84c051879013624504175e44
MD5 67449595dfccedbea3f036facf50ba9d
BLAKE2b-256 b6ceb3444c98eab123b7348d55d4705c2f1095a6bdf8dae85bc6a34ab5222845

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_xvfb-3.1.1.tar.gz:

Publisher: main.yml on The-Compiler/pytest-xvfb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_xvfb-3.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_xvfb-3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_xvfb-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3270f91417cfa0652b7c5a90e93a676e3a80bec12ccbd20cae3b42511e4aba98
MD5 4f7a18249e46e66c41dd32df79210876
BLAKE2b-256 266e859b1e496671fb236153c2caed519301c53f7cf3dfcaac809caae695b5a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_xvfb-3.1.1-py3-none-any.whl:

Publisher: main.yml on The-Compiler/pytest-xvfb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page