1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
===========
pytest-venv
===========
.. image:: https://img.shields.io/pypi/v/pytest-venv.svg
:target: https://pypi.python.org/pypi/pytest-venv
.. image:: https://github.com/mmerickel/pytest-venv/actions/workflows/ci-tests.yml/badge.svg?branch=main
:target: https://github.com/mmerickel/pytest-venv/actions/workflows/ci-tests.yml?query=branch%3Amain
``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
=====
.. code-block:: python
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.
|