How msinamsina/pytest-pyvenv works
Project type and purpose
• This is an open-source plugin for pytest (a testing framework) that provides a pyvenv fixture for creating and manipulating Python virtual environments inside test functions.
• Key indicators:
• src/pytest_pyvenv holds plugin code
• tests/ contains unit tests around venv creation
• README describes a pytest fixture usage
File structure
• Top-level directories:
• .github/workflows/ – CI pipelines (run tests, publish)
• src/pytest_pyvenv/ – core plugin implementation
• docs/ – Sphinx documentation
• tests/ – test suite for the plugin
• Packaging/configuration:
• pyproject.toml, requirements.txt, Makefile, pytest.ini
• Sphinx conf in docs/conf.py
• Patterns & concerns:
• pytest plugin entry via setuptools entry points
• venv management via Python’s stdlib venv module
• subprocess calls for installing packages and running commands
README for additional insights
• Describes the pyvenv fixture that:
1) creates a virtual environment
2) installs packages via install_package(...)
3) runs arbitrary shell commands in that env via run(...)
a. Main components
• Test Code – uses the pyvenv fixture
• pytest Core – loads plugins, manages fixtures
• pytest_pyvenv Plugin
– entry point (setuptools hook)
– VenvManager class
– methods: create(), install_package(), run()
• Python stdlib venv – actually builds the virtual environment
• Virtual Environment FS – isolated site-packages, bin/python
• External services
– PyPI registry (for pip install)
– OS shell for running commands
• Support systems (not in runtime)
– Sphinx docs builder
– GitHub Actions CI
b. Relationships & interactions
1) pytest test runner invokes test functions
2) pyvenv fixture is requested → plugin code runs
3) Plugin calls venv.EnvBuilder to create venv directory
4) Plugin uses subprocess (pip) to install packages into that venv
5) Test code calls pyvenv.run(...) → subprocess within venv
6) Tests assert outcomes
7) CI pipeline triggers the entire workflow automatically
c. Architectural patterns & design principles
• Plugin & fixture pattern (pytest hooks)
• Single‐responsibility: VenvManager handles isolation, installation, execution
• Dependency inversion: relies on stdlib venv and subprocess rather than reinventing venv logic
• Separation of concerns: docs, code, tests, and CI are all distinct layers
d. Key technologies & libraries
• Python 3.x stdlib: venv, subprocess
• pytest plugin interface
• setuptools entry points (declared in pyproject.toml)
• Sphinx for docs (conf.py + templates)
• GitHub Actions for CI