Skip to main content

py.test fixture for creating a virtual environment

Project description

https://img.shields.io/pypi/v/pytest-venv.svg https://img.shields.io/travis/mmerickel/pytest-venv.svg

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)

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)

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

get_version(pkg_name)

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

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.

Download files

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

Files for pytest-venv, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size pytest_venv-0.2.1-py2.py3-none-any.whl (4.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pytest-venv-0.2.1.tar.gz (6.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page