Skip to main content
https://img.shields.io/pypi/v/pytest-venv.svg https://github.com/mmerickel/pytest-venv/actions/workflows/ci-tests.yml/badge.svg?branch=main

pytest-venv is a simple pytest plugin that exposes a venv fixture. The fixture is used to create a new virtual environment which can be used to install packages and run commands inside tests.

Usage

import os

def test_it(venv):
    venv.install('pyramid', upgrade=True)
    subprocess.check_call(
        [os.path.join(venv.bin, 'pserve'), 'development.ini'],
    )

API

The venv fixture is an instance of pytest_venv.VirtualEnvironment(path) which exposes the following API:

path

The path to the virtualenv directory.

bin

The path to the bin / Scripts directory.

python

The path to the python executable in the virtualenv.

create(system_site_packages=False, python=None, *, extra_args=None)

Create a virtualenv. This is called automatically by the venv fixture. If python is None then the virtual environment will be created using the same executable as the active runtime.

install(pkg_name, editable=False, upgrade=False, *, extra_args=None)

Use pip to install a package into the virtualenv. pkg_name may be a path to a package on disk.

get_version(pkg_name, *, raises=True)

Returns a packaging.version.Version object which is sortable and convertable to a string.

0.3 (2023-11-22)

  • Drop Python 2.7, 3.4, 3.5, 3.6.

  • Add support for Python 3.9, 3.10, 3.11, 3.12.

  • No longer expect pkg_resources to be available in the created virtualenv.

  • No longer depend on setuptools.

  • Add extra_args to install() and create() to pass extra arguments to the underlying commands.

  • Add raises=False option to get_version() to avoid raising an exception if a package is not installed.

0.2.1 (2020-08-04)

0.2 (2016-11-27)

  • Add VirtualEnvironment.get_version for querying versions from installed packages in the virtual environment.

  • Support custom python interpreter paths via VirtualEnvironment.create(python=...).

0.1.1 (2016-11-27)

  • Ensure the virtual environment is started with the same Python executable as the current process.

0.1 (2016-11-27)

  • Initial release.

Release files for pytest-venv 0.3

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-venv 0.3
File Size Uploaded
pytest-venv-0.3.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-venv 0.3
File Interpreter ABI Platform
pytest_venv-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / pytest-venv-0.3.tar.gz

Download URL pytest-venv-0.3.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b92087bebcb3782984116ca3723c7abdb2ab5e76a75ea9397f4a4c35a544fe18
BLAKE2b-256 checksum
How to use checksums
14a374a456852035c9314d28efcb5bd7e20f7f4fc1070b4791768ed9ae3e889b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / pytest_venv-0.3-py3-none-any.whl

Download URL pytest_venv-0.3-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af2961af62107baf85c076cf4cd2ae47a7f345f88cbed9fb04fb51b694b9674e
BLAKE2b-256 checksum
How to use checksums
d32c681d81b1f339534620ac3cb37c80602613221e8bf8c47c7413c30ad20ab6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2.1

2 release files

0.2

2 release files

0.1.1

2 release files

0.1

2 release files

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