Metadata-Version: 2.3
Name: pytest-paraflow
Version: 0.1.0
Summary: Deterministic pytest test sharding across CI machines
Keywords: developer-tools,pytest-plugin,testing
Author: Sergei Konovalov
Author-email: Sergei Konovalov <l0kifs91@gmail.com>
License: MIT License
         
         Copyright (c) 2025 Sergei Konovalov
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Pytest
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Environment :: Plugins
Classifier: Natural Language :: English
Requires-Dist: pydantic-settings>=2.0.0
Requires-Dist: structlog>=25.1.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pytest>=9.0.0
Maintainer: l0kifs
Maintainer-email: l0kifs <l0kifs91@gmail.com>
Requires-Python: >=3.11
Project-URL: Homepage, https://github.com/l0kifs/pytest-paraflow
Project-URL: Documentation, https://github.com/l0kifs/pytest-paraflow/blob/main/README.md
Project-URL: Repository, https://github.com/l0kifs/pytest-paraflow.git
Project-URL: Issues, https://github.com/l0kifs/pytest-paraflow/issues
Project-URL: Changelog, https://github.com/l0kifs/pytest-paraflow/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

# pytest-paraflow

`pytest-paraflow` is a pytest plugin for deterministic test sharding across machines.

## Features

- Deterministic sharding by test identity (stable hash-based assignment).
- Group-based sharding via markers so related tests stay together.
- Dynamic shard count derived from total test count and desired shard size.

## Install

```bash
uv add pytest-paraflow
```

## Usage

Enable sharding by passing `--paraflow-shard-id` and either `--paraflow-num-shards` or `--paraflow-target-shard-size`.

### Static shard count

```bash
pytest --paraflow-shard-id=0 --paraflow-num-shards=4
```

### Dynamic shard count

```bash
pytest --paraflow-shard-id=1 --paraflow-target-shard-size=200
```

For `N` collected tests, shard count is calculated as `ceil(N / target_shard_size)`.

### Group tests by marker

```python
import pytest

@pytest.mark.paraflow_group("db")
def test_a():
    ...

@pytest.mark.paraflow_group("db")
def test_b():
    ...
```

```bash
pytest \
  --paraflow-shard-id=0 \
  --paraflow-num-shards=3 \
  --paraflow-group-marker=paraflow_group
```

Marker behavior:

- Tests with the same marker value are assigned to the same shard.
- `@pytest.mark.paraflow_group(...)` is only used when `--paraflow-group-marker=paraflow_group` is provided.
- Without `--paraflow-group-marker`, paraflow falls back to per-test (`nodeid`) sharding.
- `--paraflow-group-marker=smoke` with `@pytest.mark.smoke` groups all `smoke` tests together (single group key).
- `--paraflow-group-marker=smoke` with `@pytest.mark.smoke("db")` groups by value (for example `db`, `api`).
- `--paraflow-group-marker` is repeatable. If multiple configured markers exist on one test, the first configured marker wins.

## CLI options

- `--paraflow-shard-id`: current shard index (zero-based).
- `--paraflow-num-shards`: total shard count.
- `--paraflow-target-shard-size`: desired tests per shard for dynamic sizing.
- `--paraflow-group-marker`: marker name used for grouping (repeatable).

## Configuration defaults

CLI option defaults are loaded from `Settings` (`src/pytest_paraflow/config/settings.py`).
You can configure them via environment variables:

- `PYTEST_PARAFLOW__SHARD_ID`
- `PYTEST_PARAFLOW__NUM_SHARDS`
- `PYTEST_PARAFLOW__TARGET_SHARD_SIZE`
- `PYTEST_PARAFLOW__GROUP_MARKER` (JSON array, for example `["paraflow_group", "smoke"]`)

CLI values always override environment defaults.

## GitHub Actions (matrix sharding)

Example workflow template: `examples/paraflow-matrix-example.yml`.
Copy it into `.github/workflows/` in your repository to enable CI.

It runs pytest in 4 shards via matrix (`shard_id: [0, 1, 2, 3]`) and limits concurrent shard jobs with:

- `strategy.max-parallel: 2`
- `--paraflow-shard-id=${{ matrix.shard_id }}`
- `--paraflow-num-shards=4`

## Validation rules

- `--paraflow-shard-id` is required whenever sharding is enabled.
- One of `--paraflow-num-shards` or `--paraflow-target-shard-size` is required.
- `--paraflow-shard-id` must be in `[0, total_shards - 1]`.
