Skip to main content

A pytest plugin to execute test cases in a subprocess

Project description

pytest-insubprocess

A pytest plugin for running tests in isolated subprocesses.

Features

  • Run pytest tests in separate subprocesses for better isolation
  • Proper handling of test failures and exceptions across process boundaries
  • Maintains pytest's output formatting and reporting
  • Preserves pytest command-line options in subprocesses

Installation

You can install pytest-insubprocess via pip:

pip install pytest-insubprocess

Usage

Once installed, the plugin is automatically registered with pytest. To run your tests in subprocesses, use the --insubprocess flag:

pytest --insubprocess

Basic Example

# test_example.py
import os
import pytest

@pytest.mark.insubprocess
def test_isolated():
    print(f"Running in process: {os.getpid()}")
    assert True

Run with:

pytest test_example.py

Each test will run in its own subprocess, providing complete isolation.

Why Use This Plugin?

  • Process Isolation: Each test runs in a fresh subprocess, preventing side effects between tests
  • Resource Cleanup: Processes are terminated after each test, ensuring clean state
  • Memory Isolation: Memory leaks in one test won't affect others
  • System Resource Independence: Tests that modify system state won't interfere with each other

Requirements

  • Python 3.7 or later
  • pytest 7.0 or later

Development

To contribute to pytest-insubprocess:

  1. Clone the repository:
git clone https://github.com/pchanial/pytest-insubprocess.git
  1. Create a virtual environment and install development dependencies:
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows
pip install -e ".[test]"
  1. Run the tests:
pytest tests/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Links

Support

If you are having issues, please let us know by opening an issue on our issue tracker.

Project details


Download files

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

Source Distribution

pytest_insubprocess-1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_insubprocess-1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest_insubprocess-1.0.tar.gz.

File metadata

  • Download URL: pytest_insubprocess-1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_insubprocess-1.0.tar.gz
Algorithm Hash digest
SHA256 2b8713f7ea271fc3d7b5c2d1d7eeb6707a04a5e0402a7887ee2aba8e026dccbf
MD5 de9e8da380f9e813a6ee90316f84b08b
BLAKE2b-256 a1293be8bf1c653bd1375f4d8e93cf9e49e91cffeac567bbf5469b438d17dacb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_insubprocess-1.0.tar.gz:

Publisher: release.yml on pchanial/pytest-insubprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_insubprocess-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_insubprocess-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07fa7307be52e2b3e799a6729a27e957b65eb3bfc7fe505d61a85954c71e390d
MD5 07452dea8087ab91ce9e6ee56bf6052e
BLAKE2b-256 95f5ce738c897aeae4c8f16e27ec2c36d0c532fba668cdbe8fcafc0e922bf9a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_insubprocess-1.0-py3-none-any.whl:

Publisher: release.yml on pchanial/pytest-insubprocess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page