Skip to main content

This pytest plugin allows running each test in its own bubblewrap sandbox.

This means each test runs in its own isolated environment, no test has any side-effects on any other.

Basic Usage

Just install the plugin:

$ pip install pytest-bwrap

Then run your tests as usual, with a single added option:

$ py.test --bwrap

Each test will be run in its own sandbox.

Sandbox details

The sandbox will have its own filesystem, layed out as follows:

  • network access is blocked by default; (see “Options”)

  • the following are mounted read-only from the host system:

    • /etc/hosts and /etc/resolv.conf

    • /usr (and the accompanying /bin, /lib, /sbin, with proper handling of /usr-merge)

  • the following are mounted from the host system:

    • /dev

    • /proc

    • the current directory (that is, the root of the project you are testing)

    • the active virtualenv, if running in one

  • /tmp is a new tmpfs;

Options

Network Access

Tests can optionally be granted network access, by decorating them with pytest_bwrap.decorators.network_enabled().

Additional Read-only Directories

It is sometimes useful to have read-only directories, for example when verifying error handling in the tested functions.

This can be achieved in one of two ways:

  • decorating the test function with pytest_bwrap.decorators.read_only('/path/to/ro-dir');

  • setting the extra-ro-dirs option in the pytest configuration;

Example

A full example of how to use this plugin for testing is included.

In particular, it shows how to use the decorators as well as the pytest configuration.

You should be able to switch to that directory, then run the tests:

$ pip install -r requirements.txt
$ py.test --bwrap

All the tests should pass.

License

This project is offered under the terms of the GNU Lesser General Public License, either version 3 or any later version, see the COPYING file for details.

0.1

Initial release, with a basic feature-set to run each test in its own sandbox:

  • host file system is mounted read-only, CWD is mounted read-write;

  • network access is disabled by default but can be enabled for selected tests;

  • additional directories can be made read-only;

Release files for pytest-bwrap 0.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-bwrap 0.1.1
File Size Uploaded
pytest-bwrap-0.1.1.tar.gz 9.9 kB Details

Release files / pytest-bwrap-0.1.1.tar.gz

Download URL pytest-bwrap-0.1.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
dfc7ea75dc77fb00107a964af09bbf7721954505c5812ffe8ef97bba4a00a998
BLAKE2b-256 checksum
How to use checksums
f41ceea11970d09ce62c6ec04ecdec4bbccf5f10e5c350bf00b0cc38dbdf1fd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1

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